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

Exclude fields from admin form #209

Open
frlan opened this issue Apr 28, 2016 · 3 comments
Open

Exclude fields from admin form #209

frlan opened this issue Apr 28, 2016 · 3 comments
Labels

Comments

@frlan
Copy link

frlan commented Apr 28, 2016

I need to exclude fields from a child admin.py so I've added a exclude to the child admin class.

class BookAdmin(PolymorphicChildModelAdmin):
    base_model = Part
    exclude = (
        'SKU',
        'name',
        'unit'
    )

Unfortunately this is not removing the files from from. What is the correct way on doing this?

@vdboor vdboor added the bug label May 4, 2016
@vdboor
Copy link
Collaborator

vdboor commented May 4, 2016

That seems like an error. As workaround, you can define your own form, and provide the exclude in it's Meta options.

something like this likely works:

class BookAdminForm(forms.ModelForm):
    class Meta:
        model = ..
        exclude = (..)

@frlan
Copy link
Author

frlan commented May 6, 2016

I have tried this and this seems not to work. Maybe I messed something else up too.

@frlan
Copy link
Author

frlan commented May 14, 2016

I just retired it with a minimal example:

admin.py

from .models import Project, ArtProject, ResearchProject
from django.contrib import admin
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin

# Register your models here.

class ArtProjectAdmin(PolymorphicChildModelAdmin):
    base_model = 'ArtProject'
    fields = ('artist')

class ResearchProjectAdmin(PolymorphicChildModelAdmin):
    base_model = 'ResearchProject'

class ProjectAdmin(PolymorphicParentModelAdmin):
    base_model = 'Porject'
    child_models = (
        (ArtProject, ArtProjectAdmin),
        (ResearchProject, ResearchProjectAdmin)
    )

admin.site.register(Project)
admin.site.register(ArtProject)

models.py

from django.db import models
from polymorphic.models import PolymorphicModel

class Project(PolymorphicModel):
    topic = models.CharField(max_length=30)

class ArtProject(Project):
    artist = models.CharField(max_length=30)

class ResearchProject(Project):
    supervisor = models.CharField(max_length=30)

Maybe it helps.

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

No branches or pull requests

2 participants