Code Monkey home page Code Monkey logo

Comments (2)

gauravv7 avatar gauravv7 commented on June 5, 2024

Hey @a-roomana

Thanks for posting your query.

for the 1st, raw_id_fields is a property of ModelAdmin, not ModelForm. For such a scenario, you can either not use custom form, then raw_id_fields would work directly with ModelAdmin or you can assign a custom widget in the form you are making.
in the below lines, I am assuming your Page model would be having a field ext_user as a foreignKey to User model
ext_user = forms.ModelChoiceField( User.objects.all(), widget=ForeignKeyRawIdWidget(Album._meta.get_field("ext_user").remote_field, admin.site) )

remote_field is introduced in django 2.0 (helper-link)

for the 2nd, its a bug actually of which I am not sure yet. But a work-around is to copy excludes in the PageAdmin class as well. It works then

so the code would be like

class PageUpdateAdminForm(forms.ModelForm):
    ext_user = forms.ModelChoiceField(
        User.objects.all(),
        widget=ForeignKeyRawIdWidget(Album._meta.get_field("ext_user").remote_field, admin.site)
    )
    class Meta:
        model = Page
        exclude = ('site', 'type')

@admin.register(Page)
class PageAdmin(AdminViewMixin, admin.ModelAdmin):
	form = select2_modelform(Page, form_class=PageUpdateAdminForm)
	raw_id_fields = ('user',)
        **exclude = ('site', 'type')**

let me know if it works or not for you. Also if some problem persists, please share the code or models that you have defined.

from django-easy-select2.

gauravv7 avatar gauravv7 commented on June 5, 2024

closing this issue due to no further communication.

from django-easy-select2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.