Question: I'm working on a Django project, where I have amongst others, two models that have a relationship.

The first model describes a dish in general. It has a name and some other basic information, for instance:

```
dish(models.Model):
    name = models.CharField(max_length=100)
    short_desc = models.CharField(max_lenght=255)
    vegetarian = models.BooleanField(default=False)
    vegan = models.BooleanField(default=False)

```

The second model is related to the dish, I assume in form of a one-to-one relationship. This model contains the preparation and the ingredients. This data may change over time for the dish (e.g. preparation text is adjusted). Old versions of this text are still stored, but not connected to the dish. So the dish gets a new field, which points to the current preparation text.

```
    preparation = models.???(???)

```

So, whenever the preparation description is changed a new entry is created for the preparation and the dish's reference to the preparation is updated.

The preparation itself looks like this:

```
preparation(models.Model):
    prep_test = models.TextField()
    ingredients = models.TextField()
    last_update = models.DateTimeField()

```

As stated before, I believe that a one-to-one relation would be reasonable between the `dish` and the `preparation`.

**Is my assumption with the one-to-one relation correct and if so, how do I correctly define it?**

Answer: 
If you have multiple preparations for the dish, you don't have a one-to-one relationship by definition.

The way to define this is a ForeignKey from Preparation to Dish. (Note, Python style is that classes start with an upper case letter.)

```
class Preparation(models.Model):
    ...
    dish = models.ForeignKey('Dish')

```

Now you can do `my_dish.preparation_set.latest('last_update')` to get the latest preparation for a dish. If you add an inner Meta class to Preparation and define `get_latest_by = 'last_update')`, you can leave out the parameter to the `latest()` call.
Make sure, relations are correct otherwise you have repeating tuples in your models which is not very good practice, make your database very heavy. see relation from my perspective.

```
 class dish(models.Model):
    name = models.CharField(max_length=100)
    short_desc = models.CharField(max_lenght=255)
    vegetarian = models.BooleanField(default=False)
    vegan = models.BooleanField(default=False)

class Ingredients(models.Model):
    name = models.CharField(max_length=100)
    dish = models.ForeignKey(dish)

class preparation(models.Model):
    prep_test = models.TextField()
    last_update = models.DateTimeField()
    dish = models.OneToOneField(dish)

```