Answer the question
In order to leave comments, you need to log in
How to pass object to foreign?
I want to transfer an object to the foreignkey field so as not to draw the field on the form. That is, we send the id of the object, and this object is written to the database. Tell me how to do this, I did not find anything to work with this type of fields
Answer the question
In order to leave comments, you need to log in
Made it like this.
form_valid = form.save(commit=False)
order_start = Order.objects.get(slug=slug)
form_valid.order = order_start
form_valid.save()
class Employee(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
type = models.ForeignKey('EmployeeType')
Class EmployeeType(models.Model):
type = models.CharField(max_length=100)
employee = get_object_or_404(Employee, pk=1)
type = get_object_or_404(EmployeeType, pk=2)
employee.type = type
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question