django-forms

inline formset only save the last form

巧了我就是萌 提交于 2020-07-04 03:44:56
问题 i tried many ways and searched alot(googled) but no one worked for me . whenever i save my inlineformset it only save the last form , my models.py class Book(models.Model): book = models.CharField(max_length=20,unique=True) author = models.ForeignKey(Author,on_delete=models.CASCADE) class Author(models.Model): author = models.CharField(max_length=30,unique=True) count = models.IntegerField() this is my forms.py class AuthorForm(ModelForm): class Meta: model = Author fields = ['author','count'

How to have user log in and registration on same page using django

北慕城南 提交于 2020-07-02 11:27:22
问题 Currently I have a user log in page and a user sign up page, how can I have both of these on one single page? Base.html: <!doctype html> <head> {% block head %} <title>base</title> {% endblock %} </head> <body> {% block body %} {% endblock %} </body> </html> signup.html: {% extends 'core/base.html' %} {% block head %} <title> Sign Up</title> {% endblock %} {% block body %} <h2>Sign up</h2> <form method="post"> {% csrf_token %} {{ form.as_p }} <button type="submit">Sign up</button> </form> {%

custom template form fields django

拟墨画扇 提交于 2020-06-29 06:43:09
问题 i tried to use my own template style instead of default django form style , it work fine for creating post but doesnt work for update my formsets (inlineformset) , it also work if i use default django form style this my views.py class TitleQuestionAnswer(LoginRequiredMixin,UserPassesTestMixin,UpdateView): model = Title form_class = TitleForm template_name = 'template/update_title_question.html' def get_context_data(self,*args,**kwargs): context = super(TitleQuestionAnswer,self).get_context

Django CBV CreateView - Redirect from CreateView to last page

ⅰ亾dé卋堺 提交于 2020-06-29 03:30:11
问题 I'm learning Django and i have problem with redirecting back from CreateView I want to redirect to a BookDetail page which contains list of bookinstances which are created by CreateView. models.py: class BookInstance(models.Model): """Model representing a specific copy of a book (i.e. that can be borrowed from the library).""" id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text='Unique ID for this particular book across whole library') book = models.ForeignKey('Book', on

Django: input date format different when creating object from updating it

↘锁芯ラ 提交于 2020-06-27 20:01:20
问题 When I create an object and put the date into the input text field with dd/mm/yyyy format (witch is the format I want for my app) it works fine. But when I try to modify it (it means I get the key of that object and update it in the database), the input date format changes to yyyy-mm-dd (which I think is the default) and the is_valid() method never returns True. I have done a lot of thing including override the locale formats.py file, but it still doesnt work. Here is my settings.py: # Local

Django Forms DateInput widget not populating

风格不统一 提交于 2020-06-27 18:32:05
问题 I have a django edit form that has many fields from a model including some date fields, for a suitable format, I used a DateInput widget. Unfortunately, when we edit the object, all other fields are already populated with existing data, but the dates. The dates are in their initial state (dd/mm/yyyy) and since they are required, the user has to reenter the dates everytime they want to edit the object, even if they do not want to change the dates. does anyone have an idea on how to prepopulate

Django. How to reduce total number of coupons after each use

时光毁灭记忆、已成空白 提交于 2020-06-27 08:15:07
问题 Hey guys I am learning to develop a ecommerce website, I have a coupon model with used and max_value, which take care of max number of coupon available to use, I want to implement that in my views, such that if the coupon is redeemed more than the max_value(number of coupons), then it should show an error message. Whatever I have tried with my limited knowledge is resulting in errors. How can I increment the 'used' in views? This is in much more understandable way: users(sellers) are able to

Formset in Django Classbased CreateView

时光总嘲笑我的痴心妄想 提交于 2020-06-27 03:57:36
问题 Model class Timetable(models.Model): day = models.CharField(max_length=9,choices=timetable_choices) start = models.IntegerField() end = models.IntegerField() period = models.CharField(max_length=12) Views class Timetableadding(CreateView): model = Timetable fields = ['day','period','start' ,'end'] success_url = '/dashboard' What I need is to process a view similar to following image , NB: I am not good in js so i want a solution without the use of JS 回答1: CREATE FORMS.PY class MyForm

Formset in Django Classbased CreateView

让人想犯罪 __ 提交于 2020-06-27 03:57:05
问题 Model class Timetable(models.Model): day = models.CharField(max_length=9,choices=timetable_choices) start = models.IntegerField() end = models.IntegerField() period = models.CharField(max_length=12) Views class Timetableadding(CreateView): model = Timetable fields = ['day','period','start' ,'end'] success_url = '/dashboard' What I need is to process a view similar to following image , NB: I am not good in js so i want a solution without the use of JS 回答1: CREATE FORMS.PY class MyForm

how to make django inlineformset template

孤人 提交于 2020-06-23 16:48:07
问题 Whenever I save my inlineformset, it only saves the last form, if count=3 then my front end generates 3 fields to add books, but it only the save the last one. my models.py class Book(models.Model): book = models.CharField(max_length=20,unique=True) author = models.ForeignKey(Author,on_delete=models.CASCADE) class Author(models.Model): author = models.CharField(max_length=30,unique=True) count = models.IntegerField() this is my forms.py class AuthorForm(ModelForm): class Meta: model = Author