I have an intractable problem driving me round the bend (arg!) I suspect the problem is that my model uses a choices argument for one field - am I assigning to it incorrectly?
model:
class Attempt(models.Model):
# User attempt and results at a question
# Records their result, points to an Entry related to what they typed, records the user, ELO and variance at time
CORRECT = 'C'
WRONG = 'W'
REPORT = 'R'
A_TYPE_CHOICES = ((CORRECT, 'Right'), (WRONG, 'Wrong'), (REPORT, 'There is a problem with the question'))
user = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
entry = models.ForeignKey('Entry', on_delete=models.CASCADE)
assesment = models.CharField(max_length=1,choices=A_TYPE_CHOICES, db_index=True)
feedback = models.CharField(max_length=200, help_text="What is it about the question that makes it unclear or misleading",blank=True)
score = models.FloatField(null=True, blank=True, help_text="score of the user when this attempt was made - only recorded if variance below a certain threshold, otherwise null")
variance = models.FloatField()
created = models.DateTimeField(auto_now=True)
call to it in views:
Attempt.objects.create(user=request.user,
entry=Entry.objects.get(id=request.POST['entry_id']),
assessment=request.POST['self_assessment'],
feedback=request.POST['feedback'],
score=sp.score,
variance=sp.variance,
)
request.POST['self_assessment'] is equal to a string of either 'C','W', or 'R'.
The error I receive is:
File "C:\Users\Win7\OneDrive\Programming\Git\lang\Quiz\views\assessment.py", line 174, in question_score
variance=sp.variance,
File "C:\Users\Win7\OneDrive\Programming\VirtualEnvs\lang\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Win7\OneDrive\Programming\VirtualEnvs\lang\lib\site-packages\django\db\models\query.py", line 392, in create
obj = self.model(**kwargs)
File "C:\Users\Win7\OneDrive\Programming\VirtualEnvs\lang\lib\site-packages\django\db\models\base.py", line 571, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'assessment' is an invalid keyword argument for this function