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

Shortcut for admin inlines #41

Open
radiac opened this issue Oct 8, 2024 · 0 comments
Open

Shortcut for admin inlines #41

radiac opened this issue Oct 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@radiac
Copy link
Owner

radiac commented Oct 8, 2024

Add a shortcut for admin inlines - pick up when inlines contains a bare Model, or a model class name, and create a basic inline for it.

I'm going to say inline options are out of scope. I can think of lots of ways to implement it, but the main goals of this project are to streamline the simplest option and let you knock out prototypes quickly and cleanly by reducing boilerplate. Trying to support inline options in a decorator would make it more complicated to use and implement, and make the admin decorator harder to read.

In that spirit, I think it'll make sense to use a StackedInline with no option to override - it scales better than Tabular, so is a better default. If someone wants a Tabular they (a) know about it, and (b) they can write it out manually, it's only 4 lines.

I did wonder if adding this could confuse newcomers, but there's already a lot of special stuff in nanodjango, and convert will show them the correct way.

class SubThing(models.Model):
    thing = models.ForeignKey("Thing")
    name = models.CharField(max_length=255)

@app.admin(inlines=[SubThing, "OtherSubThing"])
class Thing(models.Model):
    name = models.CharField(max_length=255)

class OtherSubThing(models.Model):
    thing = models.ForeignKey("Thing")
    name = models.CharField(max_length=255)

Inlines will be defined and converted as:

class SubThingInline(admin.StackedInline):
    model = SubThing
    extra = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Ready
Development

No branches or pull requests

1 participant