views:

72

answers:

2

Hello there

Currently I have an app with a save method in its models.py . So I would like to change this so the models does not do the save() method, but rather have a separate view that will do this in die admin site.

Can you please direct me in the correct direction?

Thank you

A: 

Override save_model in your ModelAdmin class. The (bare) original is in django.contrib.admin.options.

Daniel Roseman
Please explain. Im still new to django
Harry
You first. What are you trying to do? Why? What have you tried already? What about my answer is not clear?
Daniel Roseman
Currently I have a save function in my Models. Now I would like to remove that save function out of the models. Perhaps to a admin_view.py file or someting. What I gather from what you are saying , I should do the save in the admin.py file right?
Harry
@Harry: You should present some code and explain...
Felix Kling
A: 

This is currently what I have done in my admin.py file:

class QuoteBulkUploadAdmin(admin.ModelAdmin):
    list_display = ('fields',)  

    def save_model(self, request, obj, form, change):
        contents = obj.fields
        new_content = []
        for line in contents.split('#'):
            #print line
            obj.name, obj.quote = line.split('<>')[0],line.split('<>')[1]
            #print obj.name + '*' + obj.quote
            # if IndexError:
            #   print 'Last correct line was: ' + obj.name + obj.quote
            # else:
            #slug = slugify('%s' % (obj.name))

            name = obj.name
            quote = obj.quote
            slug = slugify(name)
            s = Quotation(name=name, quote=quote, slug=slug)

It works except for the slugify part (it worked before in the models.py file when using self. not obj.)

Harry
What is not working for slugify? Any errors? Btw you should put this into your question.
Felix Kling