As I replied to you, setting a dynamic default value in a database level is not necessary if you are working with a framework :)
The best way, I think, is setting the value of your column in the view before saving the record.
models.py
from django.db import models
class MyModel(models.Model):
start_date = models.DateField(),
open_until = models.DateField(),
forms.py
from django.forms import ModelForm
class MyForm(forms.ModelForm):
model = MyModel
fields = ('start_date')
class view
from django.http import HttpResponse
from django.views.generic import CreateView
from .models import MyModel
MyView(CreateView):
form_class = MyForm
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
submitted_form = form.save(commit=False)
submitted_form.open_until = form.cleaned_data["start_date"]
submitted_form.save()
# return an HttpResponse here
For the previous entries, make a view to call just one time, and then loop through all the records and save the values of the new column according the value of the order column.
Something like this:
from django.http import HttpResponse
def set_open_until_values(request)
records = MyModel.objects.all()
for record in records:
record.open_until = record.start_date
record.save()
return HttpResponse("Done!!")