enable a model on Django Admin on Dreamhost - django

Hi I've created a new app (Paginas) but I cannot see inside the admin page. I've added 'paginas' to INSTALLED_APP. My admin.py is
# coding=utf-8
from django.contrib import admin
from .models import Pagina
class PaginaAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("titulo",)}
list_display = ('titulo' , 'contenido')
class Media:
js = ('/layout/grappelli/tinymce/jscripts/tiny_mce/tiny_mce.js','/layout/grappelli/tinymce_setup/tinymce_setup.js')
admin.site.register(Pagina,PaginaAdmin)
I am using passenger_wsgi.py file, I've touched tmp/restart.txt file, I've killed python process
I don't know what else can I do
The project you can see it on github https://github.com/totechess/paralisis_cerebral

What kind of error do you get when you go to your site yoursite.com/admin/
Did you add admin to INSTALLED_APPS? Note the S
....
'django.contrib.admin',
....
Perhaps your urls.py are not updated properly? What is the error?

Related

Django Upload/Download File

I am new to django. In my project I need to add user forms to upload some files and download the uploaded files.
Consider this as an online storage space.
This needs to be handled by class based views so that expansion of the views will be easy.
As of now I tried django-downloadview for objectdownloadview
https://django-downloadview.readthedocs.io/en/1.9/views/object.html
This works quite fine with the example. But I am not able to expand it for class based views for my project.
More over example is with slug I tried changing it to PK but its throwing errors.
I tried below code from django-downloadview example:-
Views.py
from django_downloadview import ObjectDownloadView
from .models import Document
default_file_view = ObjectDownloadView.as_view(model=Document)
Models.py
from django.db import models
class Document(models.Model):
slug = models.SlugField()
file = models.FileField(upload_to='object')
urls.py
from django.conf.urls import url
from .views import *
urlpatterns = [
url(r'^object/(?P<slug>[a-zA-Z0-9_-]+)/$',default_file_view,name='object'),
]
Can someone please help me here Or share a working example of simple 1 page django file upload and download stuff.
Regards,
Jaiswal

Django REST API Generics displaying improperly

Currently using a REST API and the generic views CreateUpdateDestroy, and my admin display GUI looks like this :
All the sources online that I've followed, tutorials etc get a generic view which looks much nicer.
Here is my views.py:
from rest_framework import generics
from models import Results
from serializers import ResulutsSerializer
class ResultsList(generics.ListAPIView):
queryset = Results.objects.all()
serializer_class = ResultsSerializer
class ResultsDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Results.objects.all()
serializer_class = ResultsSerializer
and urls.py:
from django.urls import path
from main import views
urlpatterns = [
path('results/', views.ResultsList.as_view()),
path('<int:pk>/', views.ResultsDetails.as_view())
]
what am I doing wrong?
It looks like you need to collect your app assets:
$ python manage.py collectstatic
# You can provide option: --settings=<your-settings-file> if you're using custom settings which is not default in manage.py
You will need to configure staticfiles settings in your Django settings module if not already configured – e.g. settings.py. Please follow documentation at:
https://docs.djangoproject.com/en/2.0/howto/static-files/
https://docs.djangoproject.com/en/2.0/ref/contrib/staticfiles/
If you are developing locally:
You should set DEBUG=True in your Django Settings Module (i.e. normally settings.py)

Change header 'Django administration' text on nginx

I followed this question's answers to change my django admin panel title header.
I tried this:
There is an easy way to set admin site header - assign it to current
admin instance in urls.py like this
admin.site.site_header = 'My admin'
But it just works when I'm running the page via Python manage.py runserver
My question is how can I change the admin title header when I'm running the site via gunicorn and nginx
writing this code at the bottom of urls.py somehow worked:
admin.site.site_header = 'My admin'
If you already have an admin.py file started wherein you have registered your particular models, you can simply adjust these values there.
your_app/admin.py
# Simple admin setup
from django.contrib import admin
from .models import MyModel
# Register model
admin.site.register(MyModel)
# Tweak admin site settings like title, header, 'View Site' URL, etc
admin.site.site_title = 'My App Admin'
admin.site.site_header = 'My App Admin'
You can find all the attributes here.
follow the below steps to customize the site header and site title text of django admin login page :
1.)First import admin module in settings.py file like as below :
from django.contrib import admin
2.)In bottom of settings.py file add these lines:
admin.site.site_header = 'MY_SITE_HEADER'
admin.site.site_title = 'MY_SITE_TITLE'
The above method works in latest version of django i.e.1.11.3 till date.
You can make changes to parts of the admin by providing a template in an admin subdir of your templates directory to override what is provided by admin.
In this case, you'd want to provide a base_site.html template. You can see what the default one looks like here: https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base_site.html

Models not showing in Admin Interface

I can not get my models to display within the Admin Interface even after registering them in django-admin.py using admin.site.register(topic).
I have registered a model class topic, but it just isn't showing up in the interface. Instead, I'm getting groups and users in the auth section and sites in the sites section.
Below is the code I currently have. Any help would be appreciated.
models.py
class topic(models.Model):
topic_name = models.CharField(max_length=30)
description=models.CharField(max_length=255,null=True, blank = True)
class Admin:
pass
def str__(self):
return '%s''--' %(self.topic_name)
admin.py
from django.contrib import admin
from edc.kds.models import *
if __name == "main":
management.execute_from_command_line()
admin.site.register(topic)
You're doing some strange stuff.
1: You have some ancient, years old class Admin syntax which isn't necessary.
2: You have a strange if __name block in there. Clearly that should raise a NameError, but assuming you actually wrote __name__ == 'main', there's your problem.
__name__ is set to 'main' only if the file is directly executed. If it's executed by django machinery, the if block will never fire, and thus admin.site.register will never be called.
Where'd you get this idea?
# urls.py
from django.conf.urls import patterns, url, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)

Django admin: Can't add app to admin

I have installed Django on my host (I use their install version 1.1.1), all is working fine.
I have created some apps and they are registered in my settings.py (I can verify this works when i visit the site, the app shows up).
In the folder of this app i have created admin.py with the following content:
from progmaticnet.page.models import Page, PageContent
from django.contrib import admin
class PageContentInline( admin.StackedInline ):
model = PageContent
extra = 1
max_num = 1
class PageAdmin( admin.ModelAdmin ):
inlines = [ PageContentInline ]
class Media:
#js = ('/site_media/js/tinymce/jscripts/tiny_mce/tiny_mce.js', '/site_media/js/tinymce/textarea.js')
admin.site.register( Page, PageAdmin )
But my app doesn't show up in the admin... It is said in the documentation that you'll need to restart the server, although i can't do that (runs on apache), i have a dispatch.fcgi with this content:
#!/usr/bin/python
import sys, os
project_sys="/home/progmati/public_html"
#add a custom python path
sys.path.insert(0, project_sys)
# set the DJANGO_SETTINGS_MODULE environment variable
os.environ['DJANGO_SETTINGS_MODULE'] = 'progmaticnet.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded")
I have killed the process and started it anew but with no avail...
Does anybody know what to do about it?
Thanks
Why is the js declaration commented out in your Media class? That looks like it'll be an invalid class definition as a result (class definitions can't be entirely empty). Try uncommenting it, or adding pass below the commented out line, like this:
class Media:
#js = ('/site_media/js/tinymce/jscripts/tiny_mce/tiny_mce.js', '/site_media/js/tinymce/textarea.js')
pass