Próbuję wydobyć atrybut pola modelu, ale oczywiście mam ścianę. Próbując zrobić to w shellu, wszystko jest okej .
Natomiast kiedy odpalam testy dostaję błąd AttributeError: module 'apps.reservations.models.Guest' has no attribute '_meta'
Kod, którego dotyczy cała zagwozdka
from faker import Faker
from apps.reservations.models import Guest
fake = Faker()
fake_profile = fake.simple_profile()
class TestingFactory():
[...]
def guest_factory(self):
COMMENT_MAX_LENGTH = Guest._meta.get_field('comment').max_length # TU JEST PROBLEM
guest, _ = Guest.objects.get_or_create(
first_name=fake_profile['name'][0],
last_name=fake_profile['name'][1],
sex=fake_profile['sex'],
birth_date=fake_profile['birth_date'],
nationality=fake.country_code(),
passport_number='AEO123456',
phone_number='+48123456789',
email=fake_profile['mail'],
comment=fake.text(max_nb_chars=COMMENT_MAX_LENGTH)
)
return guest
Co ciekawe, zorientowałem się, że kiedy próbuję hardkodować tę wartość to dostaję jeszcze inny error AttributeError: module 'apps.reservations.models.Guest' has no attribute 'objects'
- screenshot-20200726190055.png (35 KB) - ściągnięć: 4