Pablo
☺️
Josias
hey, can someone explain to me how I can have 2 different forms in the same view
Josias
I tried but give me errors, I want that i Post the info only validate and save the form that i filled
Mike
I have 2 models. Level and Question. I would like to add new somethig using slug in django shell.
I can add Question.objects.create(level_id=10, english_name='new something') it works . But I want to add using slug. For example something like that :
Question.objects.create(level_slug='first-level', english_name='new something'). But I am getting error TypeError: Question() got an unexpected keyword argument 'level_slug'. How can I fix it?
Mike
This is my models.py
class Level(models.Model):
level = models.CharField(max_length=100, unique=True)
created = models.DateTimeField(auto_now_add=True)
slug = models.SlugField(max_length=100, unique=True, null=True, blank=True)
#class Meta:
#ordering = ['level']
def __str__(self):
return self.slug
#return '{}, {}'.format(self.slug, str(self.level))
Mike
class Question(models.Model):
level = models.ForeignKey(Level, related_name="question", on_delete=models.CASCADE)
english_name = models.CharField(max_length=350, null=True, blank=True)
russian_name = models.CharField(max_length=350, null=True, blank=True)
buttons = models.TextField()
def __str__(self):
return self.english_name
#return '{}, {}'.format(level, english_name)
Anonymous
Ghorz
Денис
class Question(models.Model):
level = models.ForeignKey(Level, related_name="question", on_delete=models.CASCADE)
english_name = models.CharField(max_length=350, null=True, blank=True)
russian_name = models.CharField(max_length=350, null=True, blank=True)
buttons = models.TextField()
def __str__(self):
return self.english_name
#return '{}, {}'.format(level, english_name)
There are some things that concern me in this code.
First: related_name in ForeignKey is recommended to be in plural, say, 'questions', because this is OneToMany relationship.
Second: english_name and russian_name is a redundancy for a database. You should probably use Django's internationalization mechanics instead, translating the data in views according to current user's language. This is described in docs.
And third: what's the purpose of buttons? If this is a list of something, you might probably create a separate model and relate it to Question via ManyToManyField.
Денис
Anonymous
any devloper from ahmedabad,gujrat,india
Anonymous
i need supprot for m,y first project
Anonymous
Need help in rest API login
m0nte cr1st0
Help pls https://stackoverflow.com/questions/58317948/how-to-run-a-group-of-celery-tasks-apps-arent-loaded-yet
Дмитрий
Help me please. I have model shop with open, close time fields how can i get http responce with 1 if now its open and 0 if closed?
Денис
Дмитрий
yes time check by current time
Дмитрий
Денис
thx man )
datetime objects comparison is not what i can help you with and not a Django-related question as well
Денис
but nevermind
Дмитрий
i need just so get serializers related with datetime.now() in range open - close then True
Дмитрий
as i see it
Денис
probably. I can't dig into it right now
Дмитрий
i got it already no problem thx anyway )
Kannan
Hi guys,In django how to read outlook emails? If anyone knows share
Kumar
Hi, plz tell me the advantages and disadvantages of using sqlite in django
inchidi
Kumar
Nikhil
I am new to django...how should I start
Nikhil
Help please
inchidi
Anonymous
Hi
Mirco
!rules
Doragonsureiyā
Read the rules before any activity: @PythonRules
Nikhil
Sorry
Mirco
no worries
Nikhil
Ohkk now my code is exactly like on newBoston when I give command of run server it says
==OS error(Winerror 123) the file name or directory or volume label syntax Is incorrect
Nikhil
What to do now
Nikhil
It also says something like <frozen importlib._bootstrap>
Nikhil
And when I give command of make migrations it says no module name - same as my app name
Mirco
Did u activate virtualenv ?
Nikhil
I thought pycharm already made virtual environment for me
Mirco
Nikhil
Ohkk, I can do this thing
1) open pycharm
2) make virtual env
3) start new site and new all and then do coding part
Nikhil
Is that
Nikhil
Thank you for that... I have to install virtual env that worked
Mirco
😊
Sai
Getting stucked by celery in django.
Logs are not showing bon terminal at specific time
Sai
How to automate the tasks ?
Mirco
Share your code 😁
Mirco
Use pastebin and similar
Mirco
Nope
Mirco
!rules
Doragonsureiyā
Read the rules before any activity: @PythonRules
Mirco
Mirco
where's your custom model or ModelAdmin ?
Mirco
u also need the custom model
Jason
We need to register a receiver somewhere??
Mike
Денис
Mike
Денис
Денис
with a double underscore
Mike
Mike
Oh. I see now.
Probably level__slug
Question.objects.create(level__slug='adoption', english_name='something new')
TypeError: Question() got an unexpected keyword argument 'level__slug'
Денис
Mike
Денис
Денис
if you create your Level object beforehand, then you can save the Question without commit=False as your object doesn't need to wait for anything else.
Jason
How to save profile url to the custom user model in django rest auth.
Mike
Денис