These are chat archives for django/django

10th
Sep 2018
arpit anand
@mjarpitanand
Sep 10 2018 07:51 UTC
@morenoh149 Helllo Harry thanks for taking time and replying me, but it wont work Lets say i have a url
.com/search/procedure=Lower+Face
and then in my view i took this
procedure = request.GET.get("procedure");
and this procedure if I use like
procedure.objects.all();
It will give me an error like procedure is not a model which is obviously not Model name is LOWER FACE as it can be shown in URL
Any other can help please ???
Frank Godo
@frankintrahouse
Sep 10 2018 08:34 UTC
You should do: globals()[procedure].objects.all()
Please note that class names can not contain spaces (procedure=Lower+Face is url-decoded to "Lower Face" which is an invalid class name)
Frank Godo
@frankintrahouse
Sep 10 2018 08:39 UTC
@mjarpitanand Also, you should validate the input from the procedure variable. Only allow the model names that you will serve on the endpoint
arpit anand
@mjarpitanand
Sep 10 2018 10:16 UTC
@frankintrahouse Thanks mate i will try this yes it is coming from select box and i will be replacing whilespaces and all valiation.
arpit anand
@mjarpitanand
Sep 10 2018 10:23 UTC
@frankintrahouse Yes it worked, one last help, when
.com/search/procedure=Lower+Face
and i want to use this variable in Data.objects.filter(procedure__gte=0);
i want to pass in filterData.objects.filter(procedure__gte=0);
Frank Godo
@frankintrahouse
Sep 10 2018 11:23 UTC
OK, that would probably need to be like:
kw = (procedure + '__gte').lower()
kwargs = {kw: 0}
Data.objects.filter(**kwargs)
arpit anand
@mjarpitanand
Sep 10 2018 11:51 UTC
THanks again @frankintrahouse i will try this now
arpit anand
@mjarpitanand
Sep 10 2018 12:18 UTC
THanks for taking time and helping @frankintrahouse , that workeed.
Frank Godo
@frankintrahouse
Sep 10 2018 12:19 UTC
No problem, glad to help :)
arpit anand
@mjarpitanand
Sep 10 2018 12:20 UTC
:)
mpachas
@mpachas
Sep 10 2018 12:51 UTC
Hi! I had some fields in my models.py from a third-party app. Now I don't want to use them anymore, I've changed them in my models and removed the app of installed_apps then I created an run the migrations. Then I uninstalled that package, but I can't start my server, I get a ModuleNotFoundError
fsecada01
@fsecada01
Sep 10 2018 12:53 UTC

You are likely still referencing the module in your models/forms/views.py files, so you should probably lint through them. You can avoid using unused model fields by creating a proxy model and then declaring your chosen fields.

https://docs.djangoproject.com/en/2.1/topics/db/models/#proxy-models

mpachas
@mpachas
Sep 10 2018 16:12 UTC
@fsecada01 The only clue of that package is on migrations/0001_initial.py and in 0002_auto_date.py. I’m not using it, I’m pretty sure of that. It makes sense I have to keep that package installed because I used once (and removed) a field given by that package??
fsecada01
@fsecada01
Sep 10 2018 16:13 UTC
If you actually do not use the module in any way other than having an orphaned field in your SQL database, then get rid of it.
mpachas
@mpachas
Sep 10 2018 16:15 UTC
I’m trying
Cristian Samaniego
@chrisRubiano
Sep 10 2018 17:50 UTC

how can i use context template variables inside custom tags?
in my views.py i have context_dict['progreso'] = progreso
and in my templatetags folder I have a file named multiply.py with

from django import template

register = template.Library()

@register.simple_tag()
def multiply(progreso, cantidad, *args, **kwargs):
    if not progreso:
        progreso = 0
    return int(progreso) * cantidad

but when i use {% multiply progeso 3.6 %} in my template, the variable progreso is an empty string and anywhere else inside that template when i use {{ progreso }} it gets the value right

Lebzanwa
@Lebzanwa
Sep 10 2018 19:01 UTC
Guys please...
Harry Moreno
@morenoh149
Sep 10 2018 20:49 UTC
@Lebzanwa what
Harry Moreno
@morenoh149
Sep 10 2018 22:21 UTC
has anyone built a PWA with django? any special considerations or pitfalls you all can share?
what's so great about tastypie?