These are chat archives for django/django

8th
Nov 2016
Maksym L
@maksymx
Nov 08 2016 10:47
Hi all! I'm trying to make a package for my project following by https://docs.djangoproject.com/en/1.10/intro/reusable-apps/
I have a question: is it possible to install such package without settings.py?
I mean, while it is inside project directory - everything installs OK, but when I want to install it without settings - installation fails.
I need to install it first and then use it on different environments with different settings.
Thanks
Filip Figiel
@megapctr
Nov 08 2016 10:49
@yakudzam how does it fail?
Maksym L
@maksymx
Nov 08 2016 10:54
@megapctr
raise ImproperlyConfigured("settings.DATABASES is improperly configured. " django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
I've splitted common and env-special settings to settings.py and local_settings.py
Filip Figiel
@megapctr
Nov 08 2016 10:55
well this is the problem with settings in the project that wants to use your package
Maksym L
@maksymx
Nov 08 2016 10:55
so this error is raised from local_settings.py because it contains env-special data
Filip Figiel
@megapctr
Nov 08 2016 10:56
you shouldn't put settings in your reusable package
if you want to write a reusable package, it should just import django.conf.settings and use that
it'll resolve to the settings of the project which uses that package
Maksym L
@maksymx
Nov 08 2016 10:57
@megapctr hmm, OK, I'll try
thanks
Ghost
@ghost~582181f0d73408ce4f346f30
Nov 08 2016 12:26
Hello
Asif Saif Uddin
@auvipy
Nov 08 2016 12:54
hi
Slava
@scream4ik
Nov 08 2016 12:54
hello
Asif Saif Uddin
@auvipy
Nov 08 2016 12:55
I am trying to create an API like facebook's event app
to implement user count like going/interested/not going
what association/approach do you suggest?
axelkav
@axelkav
Nov 08 2016 12:55
hello
Asif Saif Uddin
@auvipy
Nov 08 2016 12:55
really appreciate your help/suggestions
MinJae Kwon
@mingrammer
Nov 08 2016 13:00
Do you wanna build a Rest Api?
Asif Saif Uddin
@auvipy
Nov 08 2016 13:00
yep using django REST framework too
MinJae Kwon
@mingrammer
Nov 08 2016 13:03
I've never used the DRF. But that seems simple ideas. You could just set 3 states (going/interested/not going) and make row for that. Then you can count that.
Asif Saif Uddin
@auvipy
Nov 08 2016 13:05
I used CHOICES in the field
is that OK or 3 different field for going. interested and not interested
can I cunt the CHOICES input?
MinJae Kwon
@mingrammer
Nov 08 2016 13:08
You could just count the filtered query results
Sherif O.
@shadowsyntax
Nov 08 2016 13:09
what’s best practices when it comes to debugging in django. I want to be able to view my variables and call stack …. any ideas?
MinJae Kwon
@mingrammer
Nov 08 2016 13:09
Just filtering query by specific choice value
Asif Saif Uddin
@auvipy
Nov 08 2016 13:09
lass Attendance(models.Model):
INTERESTED = 'IR'
GOING = 'GO'
NOTINTERESTED = 'NO'
INTEREST_CHOICES = (
(INTERESTED, 'interested'),
(GOING, 'going'),
(NOTINTERESTED, 'notinterested')
)
invited_user = models.ForeignKey(User, on_delete=models.CASCADE)
interest = models.CharField(max_length=3, choices= INTEREST_CHOICES, default= INTERESTED)
number_of_attendee = models.IntegerField()
so I can filter choice values? can you point django docs for that?
MinJae Kwon
@mingrammer
Nov 08 2016 13:10
Do you using the ORM?
Asif Saif Uddin
@auvipy
Nov 08 2016 13:11
yes I use django orm
MinJae Kwon
@mingrammer
Nov 08 2016 13:11
So, you can this 'YourModel.objects.filter()'
Fill in the filter condition with your choice comparison expression
YourModel.objects.filter(type='specific type')
Sherif O.
@shadowsyntax
Nov 08 2016 13:14
temp = RefGen.objects.filter(ref_number__isnull=False).latest('ref_number’)
what wil be my return type?
MinJae Kwon
@mingrammer
Nov 08 2016 13:14
YourModel.objects.filter(type='specific type')
Asif Saif Uddin
@auvipy
Nov 08 2016 13:14
I see
MinJae Kwon
@mingrammer
Nov 08 2016 13:15
@shadowsyntax RefGen instance
Sherif O.
@shadowsyntax
Nov 08 2016 13:17
@ming so how do i extract what i require? I was of the thought that .latest(‘ref_number') will return only the value for that header?
MinJae Kwon
@mingrammer
Nov 08 2016 13:21
Yes I know
Sherif O.
@shadowsyntax
Nov 08 2016 13:24
@ming what do u you use for debugging in python … in JS I just use the browser console ….anything like that for python of django?
Asif Saif Uddin
@auvipy
Nov 08 2016 13:24
django-debug-toolbar
Sherif O.
@shadowsyntax
Nov 08 2016 13:27
@auvipy thanks!
Asif Saif Uddin
@auvipy
Nov 08 2016 13:28
wc!
Antonis Christofides
@aptiko
Nov 08 2016 14:42
@shadowsyntax You define a kind of breakpoint by inserting this in your code: import ipdb; ipdb.set_trace. At that point it will drop you in the debugger's shell, where you can enter n (next) for step over, s for step into, or type normal Python commands to examine the values of variables. bt gives you a backtrace iirc. There are also many more commands. I think '?' shows help.
tulpn
@tulpn
Nov 08 2016 16:08
Hi guys, is it possible to link the CSRF token in Django to a Session and the request.user object ? How can I modify the default CSRF behaviour ?
Radoslav Georgiev
@RadoRado
Nov 08 2016 16:09
@tulpn you want csrf token and session id to have the same value?
tulpn
@tulpn
Nov 08 2016 16:11
@RadoRado , no no, I'd like to bind the CSRF Token to the SessionID and the User
If you have a look at https://docs.djangoproject.com/en/1.10/ref/csrf/#is-the-fact-that-django-s-csrf-protection-isn-t-linked-to-a-session-a-problem, Django has "disabled" that by design, however in our website, this poses a big security problem
Radoslav Georgiev
@RadoRado
Nov 08 2016 16:13
something like csrf_token = f(session_id) ?
Radoslav Georgiev
@RadoRado
Nov 08 2016 16:18
I guess you need to look at the CSRFMiddleware and create something of your own / extend the existing one - https://github.com/django/django/blob/master/django/middleware/csrf.py
tulpn
@tulpn
Nov 08 2016 16:20
I see, I was scared that this is the only option. I googled for a while but could not find any already made custom solutions. Thanks @RadoRado
Radoslav Georgiev
@RadoRado
Nov 08 2016 16:21
Maybe there are other options but first I'd check what's actually happening in the middlewares
Sherif O.
@shadowsyntax
Nov 08 2016 21:20
thanks!! @aptiko