I'm trying to use a simple abstract base class in django's admin interface with neo4django.
Example models.py
from neo4django.db import models
class Parent(models.NodeModel):
name = models.StringProperty()
class Meta:
abstract = True
class Child(Parent):
pass
Example admin.py:
from neo4django import admin
from core.models import Child
class ChildAdmin(admin.ModelAdmin):
pass
admin.site.register(Child, ChildAdmin)
The 'name' field doesn't appear in the admin interface.
If I use the same basic structure, but with django.db instead of neo4django.db, it all works fine. Anyone spot where I've gone wrong?
Update from comments:
This has been tried with django 1.5.5 and 1.5.4
The neo4django version is from the github repo
Registering the model with or without a ModelAdmin have both been tried and made no difference
Have you tried just registering the model, without the ModelAdmin?
Related
I am unable to design an edit function though I have made putting data into the form and rendering it through an HTML file I have made function to delete also but I have no clue of how to edit.
this is model
from django.db import models
class Person(models.Model):
name=models.CharField(max_length=50)
email=models.EmailField(max_length=30)
this is form
from .models import Person
from django import forms
class Formm(forms.ModelForm):
class Meta:
model=Person
fields=('name','email')
I'm new to Django and I would like to change the table that is on the admin site.
Now there is an User class and a Group class, I would like to add my own class, 'Games', to the admin site which have the variables 'name' and 'size'.
The class 'Games' is in my models.py.
How do I do this?
Add this to your admin.py file
from django.contrib import admin
from .models import *
class Gamesadmin(admin.ModelAdmin):
class Meta:
model = Games
fields = ('name','size',)
admin.site.register(Games,Gamesadmin)
Do not forget to use your class name correctly . Good Luck.
I have an abstract model, I'm writing a migration for all the subclasses. Instead of writing copies for each subclass I wanted to get all the subclasses of the abstract and apply the same action to them in a loop.
MyAbstractModel = apps.get_model("my_app", "MyAbstractModel")
subclasses = MyAbstractModel.__subclasses__()
But when I try to run the migration, I get:
LookupError: No installed app with label 'my_app'
How can I get the abstract model with apps.get_model so that I can call the subclasses on it?
If I do import the class directly with from my_app.models import MyAbstractModel then MyAbstractModel.__subclasses__() and all subsequent code works fine, but according to django docs, I should use apps.get_model()
I'm working in a form with a m2m field. I want that this field looks like the horizontal interface of the django admin site... ¿how i can do it?
thanks...
You need to use the FilteredSelectMultiple widget
from django.contrib.admin.widgets import FilteredSelectMultiple
from django import forms
from .models import Person
class PersonForm(forms.ModelForm):
some_field = forms.ModelMultipleChoiceField(Person.objects.all(), widget=FilteredSelectMultiple("Person", False, attrs={'rows':'2'}))
class Meta:
model = Person
You will also need to include the Javascript and CSS used in the admin. Here's an example
I've installed a django reusable app (Django-Userena) and would like to overwrite the given models.py file.
I have created an app named 'accounts' that calls from Django-Userena. In my 'accounts' app, I have this models.py file that has a class MyProfile that inherits from Django-Userena class UserenaBaseProfile - class MyProfile(UserenaBaseProfile)
In the UserenaBaseProfile class, there is the following code:
privacy = models.CharField(_('privacy'),
max_length=15,
choices=PRIVACY_CHOICES,
default=userena_settings.USERENA_DEFAULT_PRIVACY,
help_text = _('Designates who can view your profile.'))
I would like to extend privacy with an extra value with 'editable=False,' as I do not want this field to be displayed in the auto-generated form.
I tried several ways like calling privacy again in the MyProfile inherited model with the new settings but I am only made aware of Django's "Field name "hiding" is not permitted" (https://docs.djangoproject.com/en/1.4/topics/db/models/#field-name-hiding-is-not-permitted)
My current solution is to simply include the whole UserenaBaseProfile class in my 'accounts' app models.py before calling class MyProfile(UserenaBaseProfile) below.
This does not look like an elegant solution to me. How do you guys go about overriding the models.py file in the reusable app?
Thank you very much.
In my opinion it could be done in two ways:
Make a fork of Django-Userena with your modified model and you use yours.
Make a wrapper of Django-Userena with your models.py and use your wrapper app.
For the urls.py/views.py you could just put:
#Your wrapper views:
from django-userena.views import *
#your wrapper urls:
from django-userena.urls import *
Here are your models:
#your MODIFIED model:
from django-userena.models import *
# then put you new UserenaBaseProfile
class UserenaBaseProfile(models.Model):
#copy the model fields
...
privacy = models.CharField(_('privacy'),
max_length=15,
choices=PRIVACY_CHOICES,
default=userena_settings.USERENA_DEFAULT_PRIVACY,
help_text = _('Designates who can view your profile.'))
Then you could use your custom app in your project.
If you want to customise templates, create a templates directory in your project and put there your modified template files keeping their original names, so the django template-loader could find yours first (it depends how template-loaders have been configured in your settings.py)