Monday, February 29, 2016

Re: Why not working ?

Please be more specific. What isn't working? What is the desired vs actual result?

On Monday, February 29, 2016 at 8:39:54 AM UTC-8, setivo...@gmail.com wrote:

my model
.........................

class Translator(models.Model):
    """
    Model for dictionaries tranlations
    """

    def dispatch_dictionary_media_files(instance, filename):
        return 'app_dictionaries/{0}/{1}'.format(instance.name.__str__(), filename)

    author = models.ForeignKey(settings.AUTH_USER_MODEL)
    name = models.CharField('Name of translator', max_length=50, unique=True)
    language_origin = models.CharField('Origin language', max_length=30, choices=LANGUAGES)
    language_translation = models.CharField('Language of translation', max_length=30, choices=LANGUAGES)
    picture = models.ImageField('Picture for translator', upload_to=dispatch_dictionary_media_files, blank=True, null=True)
    description = models.TextField('Description of translator', null=True, blank=True)
    slug_name = models.SlugField('Name for link', unique=True)
    rating = models.DecimalField('Rating', max_digits=4, decimal_places=2, editable=False, default=0)
    date_added = models.DateTimeField('Date added', auto_now_add=True)


my admin.py
--------------------------------------

class AdminTranslator(admin.ModelAdmin):
    fieldsets = [
        ('Requred fields', {
            'fields': ['name', 'author', ('slug_name', 'language_translation')],
        }),
        ('Not required fields', {
            'classes': ('collapse',),
            'fields': ['description', 'picture'],
            'description': 'It is fields nor required. And you may skip it.',
        }),
    ]
    date_hierarchy = 'date_added'
    actions_on_top = True
    actions_on_bottom = True
    empty_value_display = '-empty-'
    prepopulated_fields = {"slug_name": ("name",)}

    inlines = [AddTranslationInline]

    # -----------------------------------------
    list_display = ['name', 'author', 'language_origin', 'language_translation', 'rating', 'was_added_recently', 'date_added']
    list_filter = ['date_added']
    search_fields = ['name']

admin.site.register(Translator, AdminTranslator)






--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bfc00154-a4f5-482b-98fd-ab4fb6ee46cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment