Hello I wanted to display the next available primary key for the table that the form is creating. There will be other forms that they will need to select that value from a drop down.
my current view class:
class AreaForm(forms.ModelForm):
@staticmethod
def get_next_id():
objs = Area.objects.all()
ret = objs.aggregate(Max('area_id'))['id__max'] + 1 if objs else 1
return ret
area = forms.CharField(max_length=50, initial=get_next_id)
area.disabled = True
short_name = forms.CharField(max_length=50)
class Meta:
model = Area
fields = '__all__'
however everything Ive tried here the value in the textbox is always the object (<staticmethod object at 0x0000021D565CC760>) instead of the actual value