django FileBrowseField shows as CharField - django

I have downloaded django-filebrowser 3.4.3 (no grapelli) and all installation steps went OK.
However when I add a FileBrowseField in my model, it shows as a CharField. I don't want that!
It should show me a FileBrowseField
models.py
from django.db import models
from filebrowser.fields import FileBrowseField
class Logo(models.Model):
logo = FileBrowseField(max_length=250)
admin.py
from django.contrib import admin
from django.db import models
from models import Logo
class LogoAdmin(admin.ModelAdmin):
list_display = ['logo']
admin.site.register(Logo, LogoAdmin)
please help!!

So it seems that I was missing an image in the /static/filebrowser/img folder. It's the image you click on to open the browser. I've added the image and linked to it from the correct template: /templates/filebrowser/custom_field.html

Related

How to add a new field to oscar dashboard

After following various examples here on stackoverflow my new field isn't showing up on django oscar dashboard here are my models and dashboard fork.
catalogue
models.py
from django.db import models
from oscar.apps.catalogue.abstract_models import AbstractProduct
class Product(AbstractProduct):
file = models.FileField(upload_to='files/%Y/%m/%d')
from oscar.apps.catalogue.models import *
dashboard/catalogue/forms.py
from oscar.apps.dashboard.catalogue import forms as base_forms
class ProductForm(base_forms.ProductForm):
class Meta(base_forms.ProductForm.Meta):
fields = ('file',)
I am wondering what i did wrong for people that have faced this issue before I need help. thanks.

Have registered class on admin, but it doesn't show up

This is my admin.py. I have created the file by myself and don't know if I need to register it somewhere in settings.
from django.contrib import admin
from .models import Athlete
admin.site.register(Athlete)
This is my models.py:
from django.db import models
class Athlete(models.Model):
firstName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
Both files are in my project folder. I don't have any apps. When I go to url/admin/ I expect to be able to create and edit athletes, but I can only edit groups and users.
What more do I need to do to make Athletes editable in admin?
Add your module into settings INSTALLED_APPS list. Probably you forgot it (as you guess in your comment).

Django Admin tables not displaying correctly

Has anyone seen this before? I've tried making new apps, projects, etc.
All thats in my admin.py file is:
from django.contrib import admin
from . models import UserProfile, Tribe, Membership
# Register your models here.
admin.site.register(Tribe)
admin.site.register(Membership)
admin.site.register(UserProfile)
I've not got any static files or css in the app..?
Create a class that inherit admin.ModelAdmin, update the fields to be shown in the list_display tuple, and register TribeAdmin instead of Tribe. Do the same for the rest.
from django.contrib import admin
from . models import UserProfile, Tribe, Membership
# Register your models here.
class TribeAdmin(admin.ModelAdmin):
list_display = ('field_1', 'field_2',)
admin.site.register(Tribe, TribeAdmin)
# admin.site.register(Membership)
# admin.site.register(UserProfile)
For all the available options, have a look at the documentation or an easy to understand beginner tutorial from the DjangoBook (please note its for an outdated Django Version, but fields works with Django 1.8)
With Django 1.8 you can use.
#admin.register(Tribe)
class TribeAdmin(admin.ModelAdmin):
list_display = ('field',)

Django import-export buttons DO NOT appear in admin screen

I followed the django import-export manual but the Import Export buttons do not appear in my admin screen.
This is what I have in my admin.py. Is there anything else I need to do? I have added import-export to my settings.py.
from django.contrib import admin
from costtool import models as m
from costtool.models import UserProfile, Prices
from import_export import resources
from import_export.admin import ImportExportModelAdmin, ImportMixin
class PriceResource(resources.ModelResource):
class Meta:
model = Prices
class PriceAdmin(ImportExportModelAdmin):
resource_class = PriceResource
pass
admin.site.register(UserProfile)
admin.site.register(Prices)
Just tell the admin what ModelAdmin to use:
admin.site.register(Prices, PriceAdmin)
You can check Django's ModelAdmin doc and try to use the new register decorator if you're using Django 1.7

Can someone explain me how to get sorl-thumbnail working on the Admin page of Django?

I've got sorl-thumbnail up and running in templates with Redis to store the thumbnails. Great stuff!! However, I would like to have thumbails in my Admin. I used the example in the documentation (see below) but with no luck.
from gallery.models import Photo
from django.contrib import admin
from sorl.thumbnail.admin import AdminImageMixin
class PhotoAdmin(AdminImageMixin, admin.ModelAdmin):
pass
admin.site.register(Photo, PhotoAdmin)
What am I doing wrong?
I do something very similar and it works for me. However, I use a slightly different method, importing my admin from a utils/admin.py in my site base instead, allowing easy inheritance across my models with other apps such as django-reversion, django-guardian, and django-markitup.
gallery/admin.py:
#from django.contrib import admin
from utils import admin
from gallery.models import Photo
class PhotoAdmin(admin.ModelAdmin):
#your customizations
admin.site.register(Photo,PhotoAdmin)
utils/admin.py:
from django.contrib.admin import *
from django.db import models
from sorl.thumbnail.admin import AdminImageMixin
class ModelAdmin(AdminImageMixin, ModelAdmin):
pass
Your model's ImageFields need to be sorl's ImageField (from sorl.thumbnail.fields import ImageField) instead of the standard django.db.models.ImageField.
This field is a drop-in replacement, so just updating this should fix the issue, or at least it did for me. If you are using South for database migrations, note that it will generate one for this, which is fine.