django-forms

Django form data lost on making login required on post

可紊 提交于 2021-01-29 21:24:03
问题 In my app, I want the following behaviour: User goes to contact form url User fills up the contact form (a) If user is logged in, validate and submit the form (b) If user is not logged in, redirect to login form for logging in and then if users credentials are validated, submit the form. In my views.py , I have: @method_decorator(login_required, name='post') class ContactView(FormView): template_name = 'extras/contact.html' form_class = ContactForm def post(self, request, *args, **kwargs):

I want to edit SizeProductMapping model using Django forms but The form is not rendering - Django

断了今生、忘了曾经 提交于 2021-01-29 19:51:06
问题 I am trying to create a edit form to update the database using Django model Forms but the problem is that edit form part of the sizeProductMap.html page is not rendering when edit form ( sizeProductMap_edit ) request is made. My models are as shown below. models.py class Product(models.Model): prod_ID = models.AutoField("Product ID", primary_key=True) prod_Name = models.CharField("Product Name", max_length=30, null=False) prod_Desc = models.CharField("Product Description", max_length=2000,

How to solve method not allowed (Post) http error 405

 ̄綄美尐妖づ 提交于 2021-01-29 18:05:51
问题 Codes in views I am new to django I couldn't able to rectify where it went wrong can anyone please help me on this. class UpdateVote(LoginRequiredMixin,UpdateView): form_class = VoteForm queryset = Vote.objects.all() def get_object(self,queryset=None): vote = super().get_object(queryset) user = self.request.user if vote.user != user: raise PermissionDenied('can not change another user vote') return vote def get_success_url(self): movie_id = self.object.movie.id return reverse('core:movie

Django Pass a Form's Field to a Model's Field

守給你的承諾、 提交于 2021-01-29 17:26:58
问题 I am learning Django web framework by going through this example. In one of the view functions: def renew_book_librarian(request, pk): """View function for renewing a specific BookInstance by librarian.""" book_instance = get_object_or_404(BookInstance, pk=pk) # If this is a POST request then process the Form data if request.method == 'POST': # Create a form instance and populate it with data from the request (binding): form = RenewBookForm(request.POST) # Check if the form is valid: if form

Extraction datas from forms

随声附和 提交于 2021-01-29 13:46:54
问题 I've just start to learn Django and now I'm trying understand how to insert datas in db, how to work with datas from templates and ect. My question is about extracting datas from form(Meta class) in template. Here is my code: model class Worker(models.Model): POSITION_SHOICE = ( ('MANAGER', 'MANAGER'), ('developer', 'DEVELOPER'), ('teamlead', 'TEAMLEAD'), ('pm', 'PM'), ('hr', 'HR'), ) f_name = models.CharField(max_length=50) s_name = models.CharField(max_length=50) position = models.CharField

Django forms how to add form field attribute

谁说我不能喝 提交于 2021-01-29 11:31:38
问题 I'm using django-crispy-forms I want to add an attribute http-prefix to the outputted domain field, for example like this... <input type="text" name="domain" http-prefix> How is this possible? I can see crispy-forms has the ability to add css to a field self.helper.field_class , but I cannot see where to add an attribute to a field like my example above just http-prefix. My Form: class SchemeForm(NgModelFormMixin, forms.ModelForm): def __init__(self, *args, **kwargs): super(SchemeForm, self).

How to handle a POST request from a Django form loaded via a custom template tag?

馋奶兔 提交于 2021-01-29 08:45:48
问题 I added a Django form to my Bootstrap nav bar to be included on every page, and it renders as it should with the appropriate values. The form was added using an inclusion_tag. However, I'm now at a loss as to how to handle the request from the form. Upon submission, whichever page the user was on should reload with updated content from the form submission. For more context, see my earlier question: How to place a django form in a nav bar so that it appears on every page? 回答1: Answering my own

django-password-reset - how to set attributes

最后都变了- 提交于 2021-01-29 07:24:43
问题 I am trying to use django-password-reset (https://pypi.python.org/pypi/django-password-reset/0.2) to allow users recovering their passwords. django-password-reset provides a form where the user can enter their username or email address, and tries to find one of those in the database. In my project, the user has no username field - only the email field. Thus, I need to make it search users by the 'email' field only, and not by the 'username' field, which does not exist in my system. The

Render different date format depending on time that passed - either |timesince or |date

自作多情 提交于 2021-01-29 05:41:48
问题 Good morning. What I would like to achive is that when user posted sooner than 24h from now, I would like to have for example: Posted: 4h ago , but when it's more than 24h, it would be nice to have: Posted: November 10. First approach is doable by using: {{ post.date_posted|date:"F d, Y" }} , second one: {{ post.date_posted|timesince }} , but is there a way to "mix" them? Is is possible in Django? 回答1: I wrote my own time_utils.py in an app called custom_utils like below based on stack

django RadioSelect widget list id

末鹿安然 提交于 2021-01-29 04:34:32
问题 I currently have a RadioSelect widget on one of my form classes that I want to style with css. However the rendered widget is contained in an ul and the list has no id. What is the easiest way to add an id to the rendered list? 回答1: Subclass RadioFieldRenderer and override render method. RadioFieldRenderer is an object used by RadioSelect to enable customization of radio widgets. Example implementation that adds class to ul element: from django.utils.encoding import force_unicode from django