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?
PyQt Tree Widget, adding check boxes for dynamic removal
python func deletes previous pandas dataframes
Flask printing html to console instead of redirecting
How to add tuples y values if x values are the same?
what is the complexity of the code given below?
Apache not serving admin static files for django
Django dynamic object listing with foreign tables (many to many case)
aysncio cannot read stdin on Windows
Write multiple matches from regex to a file on a single line a certain way
one or more most frequent letter in string python
pandas - select/mask the first n elements by value
python filter files by modified time
Python, Multiprocessing: what to do if process.join() waits forever?
How to sum values in an iterator in a PySpark groupByKey()
Allauth will not save additional fields
Read Flask Session Cookie