1
我有一個django項目,其中一個模板中有兩個按鈕。這些按鈕要麼接受要麼拒絕「提議」,這是我的模型之一。我將一個POST請求從模板傳遞給我有兩個函數的視圖。如何讓這些批准和拒絕按鈕更新模型中的「approved_by_x」值?從基於函數的視圖更新對象值
模板:
<form method="post" class="login-container" action="{% url 'accept_booking' %}">
{% csrf_token %}
<input class="btn btn-primary" type="submit" value="Accept" name="Accept"/>
<input type="hidden" name="offer" value="{{ offer }}" />
</form>
<form method="post" class="login-container" action="{% url 'decline_booking' %}">
{% csrf_token %}
<input class="btn btn-primary" type="submit" value="Decline" name="Decline" />
<input type="hidden" name="offer" value="{{ offer }}" />
</form>
的觀點:
def accept_booking(pr):
offer = pr.POST.get("offer")
print(offer)
def decline_booking(pr):
offer = pr.POST.get("offer")
print(offer
的型號:
class BookingOffer(models.Model):
artist = models.ForeignKey(Artist, null=True, related_name='artist')
artist_manager = models.ForeignKey(User, default=1, limit_choices_to=
{'groups__name': 'artist_manager'})
comment = models.TextField(max_length=120, blank=True)
time_slot = models.ForeignKey('TimeSlot', null=True, blank=True)
price = models.IntegerField(null=True, blank=True)
tech_needs = models.TextField(blank=True)
approved_by_bm = models.BooleanField(default=False)
accepted_by_am = models.BooleanField(default=False)