Limit foreign key choices in select in an inline form in admin

Used request instance as temporary container for obj. Overrided Inline method formfield_for_foreignkey to modify queryset. This works at least on django 1.2.3. class RoomInline(admin.TabularInline): model = Room def formfield_for_foreignkey(self, db_field, request=None, **kwargs): field = super(RoomInline, self).formfield_for_foreignkey(db_field, request, **kwargs) if db_field.name == ‘inside_room’: if request._obj_ is not None: field.queryset = field.queryset.filter(building__exact = request._obj_) else: field.queryset = … Read more

Django Admin Show Image from Imagefield

Sure. In your model class add a method like: def image_tag(self): from django.utils.html import escape return u'<img src=”https://stackoverflow.com/questions/16307307/%s” />’ % escape(<URL to the image>) image_tag.short_description = ‘Image’ image_tag.allow_tags = True and in your admin.py add: fields = ( ‘image_tag’, ) readonly_fields = (‘image_tag’,) to your ModelAdmin. If you want to restrict the ability to edit … Read more

DateTimeField doesn’t show in admin system

If you really want to see date in the admin panel, you can add readonly_fields in admin.py: class RatingAdmin(admin.ModelAdmin): readonly_fields = (‘date’,) admin.site.register(Rating,RatingAdmin) Any field you specify will be added last after the editable fields. To control the order you can use the fields options. Additional information is available from the Django docs.

many-to-many in list display django

You may not be able to do it directly. From the documentation of list_display ManyToManyField fields aren’t supported, because that would entail executing a separate SQL statement for each row in the table. If you want to do this nonetheless, give your model a custom method, and add that method’s name to list_display. (See below … Read more

MongoDB – admin user not authorized

I was also scratching my head around the same issue, and everything worked after I set the role to be root when adding the first admin user. use admin db.createUser( { user: ‘admin’, pwd: ‘password’, roles: [ { role: ‘root’, db: ‘admin’ } ] } ); exit; If you have already created the admin user, … Read more

Batch script: how to check for admin rights

Issues blak3r / Rushyo’s solution works fine for everything except Windows 8. Running AT on Windows 8 results in: The AT command has been deprecated. Please use schtasks.exe instead. The request is not supported. (see screenshot #1) and will return %errorLevel% 1.   Research So, I went searching for other commands that require elevated permissions. … Read more