Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4125868
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:55:33+00:00 2026-05-20T23:55:33+00:00

in one of my admin forms, I override a model form field ( location

  • 0

in one of my admin forms, I override a model form field (location) in order to use a different, map specific form field (olwidget). This MapField should include a layer (InfoLayerField) that displays all other model instances but the one that is being edited at the moment. Right now, it displays all the model instances (see MyModel.objects.all()) which means, if a model is edited the current location is displayed twice.

In order to achieve this, I’d have to exclude the current edited model instance from the QuerySet used in InfoLayerField (something like MyModel.objects.exclude(pk=self.instance.pk)). But since form fields are defined as static variables, I can’t access self.instance.

Is there any way to achieve this?

# models.py
class MyModel(models.Model):
    name = models.CharField(max_length=200)
    location = models.PointField(blank=True, null=True)


# admin.py
from olwidget.fields import MapField, EditableLayerField, InfoLayerField
from olwidget.utils import get_ewkt

class MyModelAdminForm(forms.ModelForm):
    class Meta:
        model = MyModel

    location = MapField([
        EditableLayerField({
            'geometry': 'point',
            'name': 'location',
        }),
        InfoLayerField(
            [(get_ewkt(m.location), m.name) for m in MyModel.objects.all() if m.location ], {
                'geometry': 'point',
                'name': 'other locations',
                'cluster': True,
                'cluster_display': 'list',
            }
        )
    ])

class MyModelOlwidgetAdmin(admin.ModelAdmin, GeoModelAdmin):
    form = MyModelAdminForm

...

Thanks for any hint’s.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:55:34+00:00Added an answer on May 20, 2026 at 11:55 pm

    I think you just need to override the __init__ on your form:

    class MyModelAdminForm(forms.ModelForm):
        class Meta:
            model = MyModel
    
        def __init__(self,*args,**kwargs):
            super(MyModelAdminForm, self).__init__(*args,**kwargs)
            qs = MyModel.objects.exclude(pk = self.instance.pk) #grab instance.pk here
            self.fields['location'] = MapField([
                EditableLayerField({
                    'geometry': 'point',
                    'name': 'location',
                }),
                InfoLayerField(
                    [(get_ewkt(m.location), m.name) for m in qs if m.location ], {
                        'geometry': 'point',
                        'name': 'other locations',
                        'cluster': True,
                        'cluster_display': 'list',
                    }
                )
            ])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using django.contrib.admin in one of my apps. my models: class Gallery(models.Model): location =
I'm using a custom login form, the same as the one in wp-admin, the
I have a view which queries a model to populate a form: class AddServerForm(forms.Form):
I am not server admin on one of our production systems, neither do I
I've got two controllers: admin and customers, plus one more called sessions for handling
How to construct a GQL query using server side admin datastore viewer, a one
one question about PHP Development. I am building up some Form Fields for Calculations.
One of my action outputs a csv file. The problem is if a field
My c# WinForm solution contains several projects including an Admin project with several forms
I want to build a system where an admin can create forms with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.