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

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

Categories

HOME
converter
cntk
project-management
playframework
automated-tests
wampserver
goutte
deeplearning4j
height
getorgchart
xamarin-studio
lagom
game-maker-studio-1.4
jacoco
rebol2
arm-template
pyyaml
device-detection
ip-camera
plupload
android-fragmentactivity
tweets
cruisecontrol.net
jflex
tampermonkey
hash-collision
mangodb
jackson-dataformat-csv
pari
expand
hotmail
swiftcharts
honeysql
mmdrawercontroller
mms
pmwiki
issue-tracking
poco-libraries
active-model-serializers
ddms
exiftool
ical-dotnet
mediawiki-extensions
tripwire
amd
estimation
amazon-machine-learning
chrome-remote-desktop
instruction-set
cdk
polar-coordinates
emgu
cleditor
xib
json-schema-validator
multiple-file-upload
string-parsing
codesign
elastix
mpeg-4
cctray
android-viewholder
lmfit
pyopengl
ytplayerview
uos
google-hadoop
google-earth-plugin
obfuscar
cg
node-imagemagick
jstat
io.js
codeigniter-a3m
delphi-xe3
hamsterdb
healthvault
bsod
sqljdbc
robospice
leptonica
apache2.2
symphony-cms
angularjs-timeout
dropdownlistfor
n-layer
makefile-project
v4l
viewdidload
nssavepanel
ajax.beginform
nemerle
goliath
pivotal-crm
zend-form-element
msn
task-management
revision
nt4
dotproject

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