python - Django save or update model -


i using django 1.5.1 , want save or update model.

i read django document , met get_or_create method provides saving or updating. there usage like;

model.objects.get_or_create(name='firstname',surname='lastname',defaults={'birthday': date(1990, 9, 21)}) 

defaults field using getting. while setting phase, name , surname set. understand document.

so want different setting name,surname , birthday, getting name , surname excluding birthdate. not see way in document , place.

how can this?

thank you!

get_or_create provides way of getting or creating. not saving or updating. idea is: want model, , if doesn't exist, want create , it.

in django, don't have worry getting name or surname or attribute. instance of model has attributes, i.e.

instance = model.objects.get(name='firstname',surname='lastname')  print instance.birthday print instance.name print instance.surname 

an overview of idea be: model data structure set of attributes, instance particular instance of model (uniquely identified primary_key (pk), number) has specific set of attributes (e.g. name="firstname").

model.objects.get used go database , retrieve specific instance specific attribute or set of attributes.


Comments