Проверка того, что пользователь уже отправил форму в Django
class Attest(models.Model):
CURRENT_STATUS = (
('yes', 'Yes'),
('no', 'No')
)
owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.CASCADE)
value =models.CharField(max_length=200, choices=CURRENT_STATUS, default="no")
created = models.DateTimeField(auto_now_add=True)
id = models.UUIDField(default =uuid.uuid4, unique=True, primary_key=True, editable=False)
class AttestForm(ModelForm):
class Meta:
model = Attest
fields =['value']
widgets = {
'value': forms.RadioSelect()
}
{% if request.user.profile.id in ..attesters %}
<p>you have already submitted your reponse!</p>
{% elif request.user.is_authenticated %}
<h3>1. Supplier code of conduct</h3>
<p>1.1 The Supplier Code of Conduct <strong>(hereinafter referred to as the 'Code') </strong>defines minimum standards that our suppliers and anyone under their
from django import forms
from django.db import models
import uuid
from users.models import Profile
# Create your models here.
class Attest(models.Model):
CURRENT_STATUS = (
('yes', 'Yes'),
('no', 'No')
)
owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.CASCADE)
value =models.CharField(max_length=200, choices=CURRENT_STATUS, default="no")
created = models.DateTimeField(auto_now_add=True)
id = models.UUIDField(default =uuid.uuid4, unique=True, primary_key=True, editable=False)
class Meta:
unique_together = [['owner']]
def __str__(self):
return self.value
@property
def attesters(self):
queryset = self.attest_set.all().values_list('owner__id', flat=True)
return queryset
{% if request.user.profile.id in ..attesters %} Я не могу правильно построить это утверждение, потому что не уверен, что используемое свойство является правильным.
@property def attesters(self):
Буду рад, если кто-то сможет объяснить мне это лучше.
>>> profile = Profile.objects.get(username="ichinexx@xxxxx.com")
>>> print(profile)
ichinexx@xxxxx.com"
>>> print(profile.attest_set.all())
<QuerySet [<Attest: yes>]>
>>>