python - Change models with function in Django -
my app has few buttons on page. buttons make ajax call , start function in views.py. function runs , returns data user. want function run , make changes objects in model. how do this?
models.py
class stream(models.model): step = models.integerfield(default=0) ...
thanks
refer django app tutorial. can create or modify model objects given below
from myapp.models import stream #to create object stream.objects.create( city = 'chennai', ... ) #to single object unique value stream.objects.get(id = 1) #to update retrieved object some_variable = stream.objects.get(id = 1) some_variable.city = 'chennai' some_variable.save() #to filter objects given value stream.objects.filter(city = 'chennai') #to update filtered objects stream.objects.filter(city = 'chennai').update(country = 'india')
Comments
Post a Comment