python


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?

Related Links

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

Categories

HOME
fparsec
avro
docker-swarm
heap-memory
is-empty
user
jpanel
docker-windows
codeblocks
internet-explorer-11
shipping
flexbox
ndis
google-shopping
informatica-powercenter
cloudflare
eclipse-luna
lenskit
factor-analysis
google-people
google-api-java-client
boolean-expression
thingsboard
remove-method
scalajs-react
onesignal
metadata-extractor
dpi
websauna
getjson
expand
remote-server
shibboleth
issue-tracking
meta-raspberrypi
duktape
android-preferences
onmouseover
w3-total-cache
walmart-electrode
nstouchbar
sapui
istorage
shutdown
bnd
google-maps-ios
photon-controller
gce
paas
mercury
payu
rstudio-server
pydio
tuxedo
mercurial-hook
django-south
search-regex
qt-linguist
brackets-shell
asymptote
cctray
coldfusion-7
scrollspy
hiera
virus
gyroscope-framework
omnifocus
collabnet
humanizer
dache
alpha-transparency
picat
pyjade
nservicebus4
nsmatrix
socketstream
pitch
qsqltablemodel
sunspot-rails
flexicious
selectonemenu
windows-live-id
dcpu-16
symbol-server
msn
asp.net-routing
asp.net-mvc-controller
usability-testing
dirty-data
project-lifecycle

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App