-
Notifications
You must be signed in to change notification settings - Fork 13
What do you do when the create requires a lot of fields? #106
Comments
I prefer to pass necessary data as typed dictionary and define a factory method to fill default params. class ProfileData(TypedDict):
name: str
age: int
@dataclass
class Profile:
@classmethod
def create(cls, data: ProfileData):
return cls(balance=0, **data) |
ok this is the confusing part for me. i know that mappers can work with dataclass, attrs, or pydantic models. So how do i know when to use which? I did find an article that compares dataclass against attrs so I know that dataclass is a subset of attrs. What do you recommend? |
And your create is at the entity level. So what do you do at the repository level? |
Repository level if for working with a database, a REST endpoint, etc. When you already have the data you can create entities yourself. I don't see any problems with this approach. attrs, dataclasses, and pydanctic are equally supported by mappers. You can choose anything you like. But I suggest not mix them across the project. |
I had to read that a few times. But i think i understand what u mean now. You mean to say that even in the repository level, you will use a ProfileData typedDict to pass in for Yes?
What do you recommend as default for a Django app? I am on 3.7 python django 2.2 |
at https://github.com/dry-python/bookshelf/blob/master/bookshelf/repositories/profile.py#L29, i notice you pass in the
user
which is required to create theprofile
What happens when there are like a dozen required fields to create a new entity? Will you then have a dozen parameters?
The text was updated successfully, but these errors were encountered: