Skip to content

Instantly share code, notes, and snippets.

@godfather68
Created September 22, 2020 10:14
Show Gist options
  • Save godfather68/8f6939f46cabc99c3448f483b316ed64 to your computer and use it in GitHub Desktop.
Save godfather68/8f6939f46cabc99c3448f483b316ed64 to your computer and use it in GitHub Desktop.
from django import forms
from .models import Customer, Request
class CreateRequestForm(forms.ModelForm):
customer = forms.CharField()
def clean(self): # update
data = self.cleaned_data.pop('customer')
customer, created = Customer.objects.get_or_create(name=data)
self.cleaned_data.update({'customer': customer})
class Meta:
model = Request
fields = '__all__'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment