Think of a better API to define natural keys for models

Issue #6 resolved
Andy Mikhaylenko
repo owner created an issue

Model is a way to specify the structure of a certain subset of data within a storage. It defines constraints which can be used for both validation of items being saved and querying of items being already in the database. So I guess we can use the properties for both tasks in most cases.

Comments (4)

  1. Andy Mikhaylenko reporter
    • changed status to open

    Each field provides:

    • validation of incoming data;
    • validation of stored data against the model, i.e. the field contributes to query so that SomeModel.query(storage) returns only required results;
    • type conversion (backend-specific, so backend must be able to introspect the model or at least fields).

    Sometimes we'll need compound validation (e.g.: Staff = required(name OR username OR email) AND is_stuff=True). Obviously this can't be done on property level, so Meta.must_have can be used. It can be implemented as a function which expects BaseQuery subclass as an argument and returns its instance (which can be later applied to another query in order to find intersection between them).

  2. Log in to comment