How to make base models custom classes in over files. import error.

Hey!
I want to make abstract classes for models in models_set.py

from django.db import models

from .models import Recipe


class RecipeBaseModel(models.Model):
    recipe = models.ForeignKey(
        Recipe,
        verbose_name='recipe',
        on_delete=models.CASCADE,
    )

    class Meta:
        abstract = True

in models.py I want to use it:

class Recipe(…)…

class AmountOfIngredient(RecipeBaseModel):
    ingredient = models.ForeignKey(
        Ingredient,
        verbose_name='ingredient_name',
        on_delete=models.CASCADE,
    )
    amount = models.PositiveIntegerField(
        verbose_name='ingredient_amount',
        validators=(
            MinValueValidator(
                1, message='min_is 1'),),
    )

    class Meta:
        default_related_name = 'amount'
        verbose_name = 'amounts of ingredient '
        ordering = ('ingredient',)
        constraints = [
            models.UniqueConstraint(
                fields=['ingredient', 'amount'],
                name='unique_amount_ingredient'
            )
        ]

during makemigrations have got error:
ImportError: cannot import name ‘Recipe’ from ‘recipes.models’ (/Users/pavelserdiukov/Documents/Dev/foodgram-project-react/backend/recipes/models.py)

Why? And how to fix it? Thanks.

This isn’t going to work - you’re creating a circular import situation.

(If you’re importing models in models_set, you can’t then import models_set from models.)

How to fix it? Move your abstract class into models.py.

Many thanks!!! Yes, I did it before, but thinking may be over way is.