These are chat archives for django/django

20th
Dec 2017
:]
@elcolie
Dec 20 2017 02:43
@emihir0 render_contract is the correct way.
Miracle Ayodele
@iammiracle
Dec 20 2017 07:11
var setColor = function (color) {
            $('#style-color').attr("href", "{% static 'frontend/layout/css/themes/red.css' %}");
        }
hi guys, i am facing issues with using static file in this senerio
i get this error
Not Found: /{% static 'frontend/layout/css/themes/red.css' %}
[20/Dec/2017 07:06:11] "GET /%7B%%20static%20'frontend/layout/css/themes/red.css'%20%%7D HTTP/1.1" 404 2649
matrixbot
@matrixbot
Dec 20 2017 08:19
benyaminp should i use generic views/models?
benyaminp is there any compelete admin panel written for django? except built in one?
i want to create one but i have no idea where to start
Luke-VideoLibre
@LukeVideo
Dec 20 2017 08:59
@koderNeptune Where are you calling that var?
Shouldn't you be using the static url rather than a template variable. GET /%7B%%20static%20'frontend/layout/css/themes/red.css'%20%%7D
Luke-VideoLibre
@LukeVideo
Dec 20 2017 09:05
That's just looking at the string you passed as argument. It's not being modified by django. So you might want to look at static url handling and passe a proper url for the file. like "mysite/frontend/layout/css/themes/red.css"
{% load static %}
Luke-VideoLibre
@LukeVideo
Dec 20 2017 10:03
Anyone use django-zurb-foundation ?
:]
@elcolie
Dec 20 2017 10:45
Hi
I am having problem with sequence.
If pytest can not be able to do reset_sequence. I would note it to my previous post. https://stackoverflow.com/questions/44558018/django-test-vs-pytest
matrixbot
@matrixbot
Dec 20 2017 12:38
benyaminp is it possible to create a compelete self-written admin for django project?
is there any examples of it?
benyaminp is it possible to create a compelete self-written admin for django project?
is there any examples of it out there?
Miracle Ayodele
@iammiracle
Dec 20 2017 12:52
@LukeVideo the code is in a js file
Luke-VideoLibre
@LukeVideo
Dec 20 2017 12:53
So django wont see the template tags
matrixbot
@matrixbot
Dec 20 2017 12:53
benyaminp guys? answe me please
benyaminp sound's like django sux
benyaminp *answer
Miracle Ayodele
@iammiracle
Dec 20 2017 12:54
@LukeVideo the script is meant to load a particular css file when the corresponding color is clicked
but its not seeing the static file
Luke-VideoLibre
@LukeVideo
Dec 20 2017 12:56
@matrixbot I was having my meal man ! keep cool :smile: I am not sure of an easy way to do it but i read somewhere you can override the admin.
@koderNeptune template tags are evaluated before django sends your page back to the browser. So it won't evaluate what the browser handles. As far as i know
Miracle Ayodele
@iammiracle
Dec 20 2017 13:03
@LukeVideo so what do you suggest i do in this case?
matrixbot
@matrixbot
Dec 20 2017 13:10
benyaminp you know what? django sux..
Luke-VideoLibre
@LukeVideo
Dec 20 2017 13:14
I'm not sure... I might say something stupid but @emihir0 ' s solution for the contract could probably be adapted for your needs. You could build a template for your JS file and serve it with your request or so... Else you can hardcode the urls.. Witch is lame... Or initialise these as variables in your html template in a script tag... Witch is pretty hacky.
@koderNeptune
@matrixbot ok. Maybe you mean it doesn't correspond to your needs ? I'm pretty happy with it :smile:
Anish Shrestha
@annshress
Dec 20 2017 14:46
@matrixbot You can do it. I had gone through the same issue.
Rather than modifying looks and feels or f existing django admin page, I downloaded free admin templates, used Generic views and forms for CRUD operations. It's easier
Luke-VideoLibre
@LukeVideo
Dec 20 2017 14:58
Any ideas how i could add a class on the label the way i did for the widget ? forms.TextInput is the input tag in my form but how to acces the label tag ?
class documentProofForm(forms.ModelForm):

    class Meta():
        model = DocumentProof
        labels = {
            'doc' : 'document to upload :',
        }
        fields = ('name', 'doc',)
        widgets = {
            'name': forms.TextInput(attrs={'class':'cell'}),
        }
Luke-VideoLibre
@LukeVideo
Dec 20 2017 16:11
Seems to be impossible...
emihir0
@emihir0
Dec 20 2017 16:14
I prefer approach that doesn't edit widgets in Meta but directly in fields
so you'd have, for example:
class DocumentProofForm(forms.ModelForm):
    doc = forms.TextField(label=_('document to upload'), **other_kwargs)
    name = forms.TextField(widget=forms.TextInput(attrs={'class': 'cell'}), **some_other_kwargs)

    class Meta:
        model = DocumentProof
        fields = ['doc', 'name']
Luke-VideoLibre
@LukeVideo
Dec 20 2017 16:17
@emihir0 sound good. Thank's.
emihir0
@emihir0
Dec 20 2017 16:22
also, get into habit of capitalising your classes (DocumentProofForm, not documentProofForm) as that's the python-wide standard
Luke-VideoLibre
@LukeVideo
Dec 20 2017 16:28
True
lego
@legobillyjoe
Dec 20 2017 16:34

Hey boys, hey girls. Here is a question from official django polls tutorial (Part 3, Django 2.0, where we "write views that actually do something"):

What is latest_question_list? Is that an object? a variable? or maybe a List? Queryset?

Here is the code it comes from:

from django.http import HttpResponse

from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    output = ', '.join([q.question_text for q in latest_question_list])
    return HttpResponse(output)

Thanks in advance.

Luke-VideoLibre
@LukeVideo
Dec 20 2017 16:35
If i remember it's a function from the Question model
You can define custom behaviour / requests in the model.
emihir0
@emihir0
Dec 20 2017 16:48
latest_question_list is a list of 5 Question instances, ordered by pub_date in descending order (ie. not first 5 questions published, but... latest 5 questions published)
the output simply makes a string out of the Question instances that is readable by user
Marios Panagopoulos
@MariosPanag
Dec 20 2017 22:40
how can i run query once and then search inside it instead of doing another query?
Marios Panagopoulos
@MariosPanag
Dec 20 2017 22:50
nvm i found this " When QuerySets are evaluated"