django-forms

Overriding the default class attribute using django-crispy-forms

Overriding the default class attribute using django-crispy-forms Question: I am currently learning how to use django crispy forms and can’t figure out this issue. I am using it alongside bootstrap5. I have the following form : class CommentForm(forms.ModelForm): class Meta : model = Comments fields = ["comment_content"] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = …

Total answers: 2

How to restrict Django users from filling a form twice in different sessions

How to restrict Django users from filling a form twice in different sessions Question: I have a form for employees to fill their bio data, I want to restrict the employees from viewing the form more than once. That is after filling the form, you can’t view the empty form anymore, you can only follow …

Total answers: 2

Like button not recording the data

Like button not recording the data Question: I have implemented a like button onto my view_post page, but the like’s aren’t been registered. When the button is clicked the page is redirected correctly but no likes are added. views def get_post(request, slug): try: post = BlogPost.objects.get(slug=slug) except BlogPost.DoesNotExist: messages.error(request, ‘This post does not exist.’) post …

Total answers: 1

Django form.save() does not update database

Django form.save() does not update database Question: I have a Django User model with a background and a profile picture, what I want to do is give the user the ability to submit a new background photo/picture and have it saved to the database. The way I have done this is like this settings.html: {% …

Total answers: 1

Using jquery POST request to save form in django

Using jquery POST request to save form in django Question: here my form.html in this form I’m use Django model form. <div class="container"> <form action="{% url ‘add_product’ %}" id="product_form" method="POST" enctype="multipart/form-data"> {% csrf_token %} <div class="row"> <div class="col-sm-12"> <label for="">{{form.code.label}} :</label> {{form.code}} <span id="error">{{form.code.errors | striptags }}</span> </div> <div class="col-sm-12"> <label for="">{{form.company_id.label}} :</label> {{form.company_id}} <span …

Total answers: 2

How to access specific value from model choice field in django

How to access specific value from model choice field in django Question: So i have this material models which contain 3 values and can be selected from dropdown menu in the template, how can access this exact "tegangan_tarik" and "tegangan_values to be included in my output page models.py class Materials(models.Model): SAE_Number = models.CharField(max_length=64) tegangan_tarik = …

Total answers: 1

Set declined to True if approved is False

Set declined to True if approved is False Question: I am working on a project that allows student to apply to borrow book from a library and then the librarian decides to approve or decline the request. models.py class PendingRequest(models.Model): book_request = models.ForeignKey(Borrow, on_delete=models.CASCADE, null=True) member = models.ForeignKey(User, on_delete=models.CASCADE, default=None, null=True) book = models.ForeignKey(Books, on_delete=models.CASCADE, …

Total answers: 1

How to count the number of elements of each category in Django?

How to count the number of elements of each category in Django? Question: I have a list of elements. There is a ‘status’ value here. I need a code that in an HTML page will show the total number of items for each ‘status’. How to do it? For intance, there is the list in …

Total answers: 1

How to check Django Form Submission Against Value in Database Table

How to check Django Form Submission Against Value in Database Table Question: I am trying to create a function in my views.py that checks a users date submission against values already submitted to the database: def make_booking(request): if request.method == ‘POST’: form = BookingForm(request.POST) if form.is_valid(): new_date = form.cleaned_data.get("date_of_booking") existing_booking = Booking.objects.get(‘date_of_booking’).items() for booking in …

Total answers: 3

I cannot post comment in Django, no error

I cannot post comment in Django, no error Question: I’m working on a Django blog and I’m stuck here… I want to post comment and when I do that it just refresh the page and nothing happens. I have no idea where I’m making a mistake, please see my code below: this is views.py def …

Total answers: 1