4

In models.py I have

class myModel:
    period = models.CharField(max_length = 100, blank=True)

the period should contain something like: DD:HH:MM:SS.

In the HTML template, I want this field to be in four different textbox input fields. Is there a way to do this in Django?

1 Answer 1

3

This is well documented: you need to create a subclass of forms.MultiValueField, which implements a compress method which returns the combined value of the fields. Note that there is already a SplitDateTimeField, but that just have two separate fields for each of the date and time.

Sign up to request clarification or add additional context in comments.

4 Comments

Ok, i'm trying this. But when creating a subclass of forms.MultiValueFied, i got errors like : AttributeError: 'SplitPeriodField' object has no attribute 'render'. got inspired from this example stackoverflow.com/questions/8386101/…
I can't help without seeing your code or the traceback. But it sounds like you are using a field where you should be using a widget.
Thanks, it works. But I want the inputs of the split field to be horizontal? Any suggestions ?
@DanielRoseman But what if I want to do the opposite of this. like - stackoverflow.com/questions/57288620/… or stackoverflow.com/questions/57265650/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.