Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation? #16

Open
odigity opened this issue Oct 30, 2022 · 1 comment
Open

documentation? #16

odigity opened this issue Oct 30, 2022 · 1 comment

Comments

@odigity
Copy link

odigity commented Oct 30, 2022

This feature is exactly what I've been looking for, but there's a problem.

From README:

Features the application provides:

  • Creating an arbitrary number of generic relation fields, both required and optional;
  • Providing custom names for content_type and object_id columns
  • You can define a whitelist (or a black one) of models that could (not) be written into the field

That sounds great, but is there any documentation explaining how to use those features? The example in the README doesn't include any arguments.

@marazmiki
Copy link
Owner

Oh yeah, looks like we have a problem with documentation :(

But even when documentation somewhere sucks, tests could save the day. E.g. you can see some examples of declarations in test project's models.py.

In case you are sick of reading of the docs, let me show a small example. Wrote right here, didn't check.

    from django.db import models
    from generic_helpers.fields import GenericRelationField
    
    class JustModel(models.Model):
        pass   


    class ModelHavingGenericRelations(models.Model):
        gr_required = GenericRelationField()
        gr_optional = GenericRelationField(blank=True)
        gr_custom_content_type_field = GenericRelationField(ct_field="my_content_type")
        gr_custom_fk_field = GenericRelationField(fk_field="my_obj_id")
        gr_whitelist = GenericRelationField(
            allowed_content_types=[
                "JustModel",  # For models in the same app
                "contenttypes.ContentType",  # standard django app_label.model_name notation
             ])
        gr_blacklist = GenericRelationField(
            denied_content_types=[
                JustModel    # Model classes also available (AFAIR)
           ])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants