i have django project in using django-rest-auth authenticate users. settings.py:
installed_apps = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'rest_framework', #following added allow cross domain requests 'corsheaders', #following added ssl thing 'djangosecure', 'sslserver', #following added authentication 'rest_framework.authtoken', 'rest_auth', 'allauth', 'allauth.account', 'rest_auth.registration', 'demo', )
i have 2 models: exercise , rating. did not create user model must provided django-rest-auth / django.contrib.auth. user can give multiple ratings particular exercise.
my models.py following:
class exercise(models.model): #field storing exercise type exercise_type_choices = ( (1, 'best stretch'), (2, 'butterfly reverse'), (3, 'squat row'), (4, 'plank'), (5, 'push up'), (6, 'side plank'), (7, 'squat'), ) exercise_type = models.integerfield(choices=exercise_type_choices) #field storing intensity level intensity_level_choices = ( (1, 'really simple'), (2, 'rather simple'), (3, 'simple'), (4, 'okay'), (5, 'difficult'), (6, 'rather difficult'), (7, 'really difficult'), ) intensity_level = models.integerfield(choices=intensity_level_choices) #field storing video url particular exercise video_url = models.urlfield() #field storing description of exercise description = models.charfield(max_length=500) class rating(models.model): #field storing exercise type exercise = models.foreignkey(exercise, related_name='ratings', blank=true, null=true) #field storing rating rating_choices = ( ('h', 'happy'), ('n', 'neutral'), ('s', 'sad'), ) value = models.charfield(max_length=1,choices=rating_choices)
according description above rating model should contain userid foreign key along exerciseid, right?
how can achieve this? how can modify rating model? need import?
from django.contrib.auth.models import user class rating(models.model): user = models.foreignkey(user) # other fields
i think looking for. here example think related question
Comments
Post a Comment