Create function which fill automatically a field model


I use Django 3.0 and I would like to create a function which fill automatically a field in my models.
Can I do it directly in ? How?

Thanks a lot

I think you’re after the default argument to fields:

Hope that helps!

Thanks you for your answer. I know how to make a default value in charfield but I don’t know how to build function which returns value for my default field. In my case this function must retrieve last id on my model and must concataned it with a string and the final result must be affected to default charfield. Have you an example ? Help me plz

Making one field’s value default to something calculated from another field’s value is best done by overriding save() instead. See:

1 Like