How to return two values for two foreign keys in same model separately?
class student(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) class details(models.Model): first_name = models.ForeignKey(student,models.DO_NOTHING, db_column='first name', blank=True, null=True) last_name = models.ForeignKey(student,models.DO_NOTHING, db_column='second name', blank=True, null=True) Here, first name and last name are drop downs.With this piece of code drop downs shows studentObjects not first_name and last name values. we used def __str__(self): return self.first_name but dont know how to send last name. please help me out.
I don't like your data structure and I am suspicious that you don't really want to do it that way. Let's assume the following: class student(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) def __str__(self): return "%s %s" % (self.first_name, self.last_name) class details(models.Model): student = models.ForeignKey(student, models.CASCADE) That is used in order to have student objects (the students are identified by its first_name and last_name). And each details objects can be related to a single student (if you want to change the relation, do so). The relation is between student and its details. I am not sure if that is what you want to achieve, but maybe makes sense?
Django-Rest-Framework - How to serialize queryset from an unrelated model as nested serializer
Discord.py sending message twice
Crash when importing wmi.py
Reconstructing an exception from an extracted traceback
Appending unique mixed string using pandas or python
python setuptools Include man page in RPM
How do I move an empty array from a variable with multiple arrays?
Media images not showing, even though they successfully load on the page
Python Script won't run right when double-clicking .py
Frequently receiving 503 error when conducting Reddit search with PRAW
How to create an XML file with some elements containing CDATA
Python: will having python 2 and python 3 casues trouble? [duplicate]
Difference between 2 files in order
Global Dictionary Between Two Files
Python: In a for loop going through a list, how do you multiply by every other element of that list
How to set up multiple Dag directories in airflow