These are chat archives for django/django

24th
Jun 2017
Anish Shrestha
@annshress
Jun 24 2017 01:32
@asaurav025 i think realpython has some tut on this.
@flyboy1565 message is pretty clear, pass along the request from view onto the seriailzer as context = {'request': request}
Anish Shrestha
@annshress
Jun 24 2017 01:39
from your view,
overwrite the get_seriailzer_class() method and initiailze along with the request as context.
and pass the same request context from one to another seriailzer.
John
@flyboy1565
Jun 24 2017 01:40
Ok, I tried that, but then I get another error
Oh maybe that's what I'm missing
John
@flyboy1565
Jun 24 2017 01:50
@annshress , can you give me an example of where this is being done.. like a tutorial or a stack overflow
Anish Shrestha
@annshress
Jun 24 2017 01:56
https://stackoverflow.com/questions/31038742/pass-request-context-to-serializer-from-viewset-in-django-rest-framework
this is passing from viewsets to seriailzer.
And in your serializer,
def get_stores(self, obj):
        queryset = Store.objects.filter(district=obj.district_number)
        return StoreDetailSerializer(queryset, many=True, context={'request': self.context.get('request')}).data
or maybe simply,
def get_stores(self, obj):
        queryset = Store.objects.filter(district=obj.district_number)
        return StoreDetailSerializer(queryset, many=True, context=self.context).data
I am never sure about anything I write, I keep on making mistakes here and there. So give it a try.
John
@flyboy1565
Jun 24 2017 02:19
@annshress thanks so much I'll look at that hopefully it'll let me wrap my head around this
Anish Shrestha
@annshress
Jun 24 2017 02:19
Ok.
John
@flyboy1565
Jun 24 2017 05:28
@annshress , thanks again this resolved that issue.
now on to the rest of them
djangoReactGuy
@SanskarSans
Jun 24 2017 06:14
Has anyone experienced with postgres ?
psql template1
sudo su - postgres

CREATE ROLE demo superuser;

CREATE USER username;

GRANT ROOT TO username;

ALTER ROLE username WITH LOGIN;
I configured username this way
I created the database as create database database_name;
and connected to db using \connect database_name;
created the postgis_extension either
then in settings.py i configured database as
DATABASES = {
    'default': {
        "ENGINE": "django.contrib.gis.db.backends.postgis",
        "NAME": "database_name",
        "USER": "username",
        "PASSWORD": "password",
        "HOST": "localhost"
    }
}
but i am getting django.db.utils.OperationalError: FATAL: password authentication failed for user "username"
ThuyLe
@chusutunho_twitter
Jun 24 2017 06:27
Hi everyone! What is "django"?
neutralboy
@neutralboy
Jun 24 2017 06:29
ThuyLe
@chusutunho_twitter
Jun 24 2017 06:35
Thanks @neutralboy
djangoReactGuy
@SanskarSans
Jun 24 2017 10:44
Hello
anyone online?
djangoReactGuy
@SanskarSans
Jun 24 2017 10:52

what is the best option to use if my api wants to send new data each 5 second?
For example i want to develop a mobile app called nearby rent searching. In nearby
rent searching, the user should allow his/her location and the app will show the rent
based on that location. But the user wont be on the same location each time. I mean suppose
if I am on place A, i should see the rented spaces nearby that A place and I am moving here and there
and reach to another place, then the result should be shown nearby that place instead of user changing
or refreshing his/her location every time.

Do i go with websocket or redis for this or some other platform when using djangi-rest-framework for an api?

neutralboy
@neutralboy
Jun 24 2017 12:56
Google api is the best one @SanskarSans ... With some modification you can make it like what Taxi companies do
djangoReactGuy
@SanskarSans
Jun 24 2017 13:29
@neutralboy Can we use the api you are talking about in free?
neutralboy
@neutralboy
Jun 24 2017 13:30
@SanskarSans yes googlelocation API
its free, but you need to tell them that you're using it
@SanskarSans This is the link
upto 25,000 per day can use it and you wont be charged.. after that its 0.5$ per 250user per day
djangoReactGuy
@SanskarSans
Jun 24 2017 13:40
I was thinking of using django channels with redis
@neutralboy Thanks for the suggestion. I appreciate your help. I will look into it.
neutralboy
@neutralboy
Jun 24 2017 13:41
@SanskarSans I have no idea what that is! :smile: , i'm a 1st year doctor, if that helps! :sparkles:
neutralboy
@neutralboy
Jun 24 2017 13:59
I find my peace in coding and python..
peidaqi
@peidaqi
Jun 24 2017 14:12
@SanskarSans in your application I think you probably want to look into something like memcached rather than redis. redis is for data storage and you app seems to rely on high freq data
also I think it may be a better idea to cache most of the rental data on the client side rather than pushing them real time
because rental doesn't change that much, and your user wouldn't move very fast. so you could probably cache a larger radius of rental data than the user's actually seeing
djangoReactGuy
@SanskarSans
Jun 24 2017 14:20
You mean to say instead of using websocket, cache the data on the client side and if the radius changes , call an api for data of current location
@peidaqi If user is in the place A, the user will be getting the rental data let's say around radius of 5km. If the
user now crosses the radius of that 5km , call an api for new location with radius of 5km.
peidaqi
@peidaqi
Jun 24 2017 14:22
maybe I didn't understand your app, but what I mean is, say your user can see a 5km radius of rental, you can actually push 10km while he's browsing
so that your app won't have to refresh every step the user moves
because people move slowly
if your user's device has a compass, you can even have a guess where he/she's heading and cache accordingly
Felipe Campelo
@fccampelo
Jun 24 2017 19:51
hey
I'm creating my model. Where it receives a foreign key KIND. When I make the api of this model. The kind value in api is the ID. But I wanted it to be description? How can I do to send some information so foreign key?
class Question(models.Model):
    title = models.CharField(max_length=225)
    user = models.ForeignKey(User)
    description = models.TextField()
    kind = models.ForeignKey(Kind, blank=False, related_name="kind")
    STATUS_CHOICES = (
        ('Active', 'Ative'),
        ('Inactive', 'Inactive'),
    )
    status = models.CharField(
        max_length=20, choices=STATUS_CHOICES, default="Active")

    class Meta:
        verbose_name_plural = 'Questions'

    def __str__(self):
this is my model !!
Shashank Parekh
@sp1rs
Jun 24 2017 19:56
@fccampelo didn’t get your question.
Felipe Campelo
@fccampelo
Jun 24 2017 19:58
[
    {
        "id": 1,
        "title": "Teste 1",
        "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "kind": 1, ->  I want get description and not id
        "status": "Active"
    },
    {
        "id": 2,
        "title": "Python Basic",
        "description": "Quisque velit nisi, pretium ut lacinia in, elementum id enim.",
        "kind": 1,
        "status": "Active"
    }
]
this is json
Shashank Parekh
@sp1rs
Jun 24 2017 20:00

Then do something like this…

When you fetch the question.

Question.objects.filter(…).values(‘id’, ‘title’, ‘descritpion’, ‘kind__description’, ‘status’)
Felipe Campelo
@fccampelo
Jun 24 2017 20:02
ok
Felipe Campelo
@fccampelo
Jun 24 2017 20:14
in the views?
Nikhil Allamsetti
@niklul
Jun 24 2017 21:52
Hey,
abdulbahajaj
@abdulbahajaj
Jun 24 2017 21:52
hey baby
Nikhil Allamsetti
@niklul
Jun 24 2017 21:53
I'm trying to delete the user 48hrs after deactivating the account
can someone suggest how to schedule events in django