Answer the question
In order to leave comments, you need to log in
Bypass the limit on the number of characters in the form?
There is a model with a field limited to 32 characters. In the admin panel, when I enter more than 32 characters in the form field, I get a restriction message. The point is that I need to enter IDs separated by commas in this field (up to 20 characters each). Then the data from the form is processed, split(',') is executed and the received data is sent to the database via bulk_upload.
I tried to override max_length in __init__ , but this made it possible to enter more characters but not save them.
How to get around this limitation without changing the max_length for the database?
models.py
class MyModels(models.Models):
....
items = models.CharField(verbose_name=_(u'Item ID'), max_length=32)
class ItemForm(ModelForm):
class Meta:
model = MyModel
fields = ['items']
def __init__(self, *args, **kwargs):
super(ItemForm, self).__init__(*args, **kwargs)
)
self.fields["items"] = forms.CharField(
max_length=512,
)
Answer the question
In order to leave comments, you need to log in
I see two options so far:
1. Use a formset and enter several records at once (but not separated by commas).
2. Write the form yourself and parse the entered data in the view.
Entering more characters into the ModelForm field than the Model requires is like trying to pour two liters of beer into a liter can. Will not enter.
There is a model with a field limited to 32 characters.
this made it possible to enter more characters but not save them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question