Elizaveta
status - integerfield(choices:1,2 or 3, default=1) text -charfield and pub_date - datetime field
8
not solved only with an else? what I mention on the part of the queryset also depends on an else
Elizaveta
I didn't solve how to display link to change question depending on it's state
Elizaveta
it doesn't work with if either
8
then it would do if for each condition or find a pattern
Elizaveta
I just don't know how to get access to that 'state' field inside this class
8
with .dict can see all propiertis with their names or ways of obtaining them
8
'dict' without quotation marks
inchidi
what is state? its saved data? or post data?
Elizaveta
In django admin I have all questions displayed. All questions have 3 states - 1,2 and 3. So if the state is 1 or 2 - I will not be able to change the question Question - class, state - integerfield
inchidi
so its saved data right?
Elizaveta
yes
inchidi
so getting Question.objects.get(class=...) is possible
inchidi
but we need to know the class object or just the id
inchidi
class QuestionAdmin(admin.ModelAdmin): fields = ['question_text',] inlines = [ChoiceInline] actions = [make_active, make_closed, make_new, delete_selected] if 'state' == 1 or 'state' == 2: list_display_links = ['question_text',] list_display = ['question_text', 'state', 'pub_date']
i will give you the shortcut, you can leave it like this class QuestionAdmin(admin.ModelAdmin): fields = ['question_text',] inlines = [ChoiceInline] actions = [make_active, make_closed, make_new, delete_selected] ist_display_links = ['question_text',] list_display = ['question_text', 'state', 'pub_date']
inchidi
then you override get_list_display_links methon in this class
inchidi
will looks like this: class QuestionAdmin(admin.ModelAdmin): .... def get_list_display_links(self, request, list_display): if 'state' == 1 or 'state' == 2: return self.list_display_links else: return list(list_display)[:1]
Elizaveta
Thank you! I will try it
inchidi
Thank you! I will try it
it will not work yet until you implement something like this https://stackoverflow.com/a/27304574/3925477 to get your Question
Anonymous
So it will just take the primary key from school, which is the id in django
i know it's the id is the default but in my case it's the name of the school which appear in data base
Anonymous
Sec-school is name of school not id number
Anonymous
side question, it has been two weeks since i started django, i am not getting things from the first tme, is that normal ?😅 and should i learn SQL or any other database engine ? since ORM is amazing
Anonymous
I am two months into django
Anonymous
And I got into things just a couple of weeks ago. And regarding sql, you can learn the basic architecture of sql just more clarity of what you are doing.
Anonymous
Aha thanks looks like i am missing something since i started django without previous knowledge of regular expressions and database arch
Anonymous
you can try delete the __str__ function of School model and see the page again
and this stiil give the same problem 😅 it refer to the school name even if i did not pass this
inchidi
magic
Anonymous
you didnt refer school name in admins.py? its weird
in admin.py i only register my models
Anonymous
class School(models.Model): name = models.CharField(max_length=265) principal = models.CharField(max_length=256) location = models.CharField(max_length=256) class Students(models.Model): name = models.CharField(max_length=256) age = models.PositiveIntegerField() school = models.ForeignKey(School)
Anonymous
at least name should be primary key in School so it refer it automatically
inchidi
how is your admin in your admin.py looks like?
Anonymous
from django.contrib import admin from first_app.models import School, Students # Register your models here. admin.site.register(School) admin.site.register(Students)
Anonymous
you are returning the name of the model
Anonymous
consequently this will refer to the attribute name whenever you call School
Anonymous
means i should delete __str__ from School too ?
Anonymous
Yup and that what @DimasInchidi told you to do, what have not you done that ?
Anonymous
i thought he means Student model
Anonymous
mmm try deleting it from the model School then
Anonymous
fuck, it worked now
Anonymous
thanks @DimasInchidi
Anonymous
anything that returned by __str__ will represent the model's name itself, lesson learnt
Django Bot
>> Jobs - Web Applications Developer - Web Applications Developer (Remote in USA)
Django Bot
>> Blogs - Tecken loadtesting
Anonymous
Welcome aboard
Anonymous
Hi guys! I need some examples like age calculator to understand basics. Where can i find examples like this?
Lapanit ☃️
In Google?
Lapanit ☃️
Age calculator?
Lapanit ☃️
Input your age:
Lapanit ☃️
15
Lapanit ☃️
Calculating
Lapanit ☃️
Your age is 15
Hasan
raw_input :dd
Lapanit ☃️
raw_input :dd
Python 3 fam
Anonymous
Anonymous
lol
Hasan
Who is the "oldschool" here?
Lapanit ☃️
whats “oldschool”
Mohd
Who is the "oldschool" here?
Do you mean Assembly?
Hasan
It means "master". :D
Mohd
Hasan
Do you mean Assembly?
Doesn't matter. :D
Mohd
For me, I don't think so 💔
Anonymous
Who is the "oldschool" here?
Everyone who is not using django 1.8+
Anonymous
I wrote what I wanted 😅 https://github.com/blackvkng/Practice-Django/tree/master/ping
Anonymous
Anonymous
Python 3 fam
Salutations!
Tushar
can someone help me run python scripts on digital ocean
Anonymous
Ahh
Anonymous
Django I assume