Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 150879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:21:38+00:00 2026-05-11T09:21:38+00:00

I’m somewhat new to Python, Django, and I’d like some advice on how to

  • 0

I’m somewhat new to Python, Django, and I’d like some advice on how to layout the code I’d like to write.

I have the model written that allows a file to be uploaded. In the models save method I’m checking if the file has a specific extension. If it has an XML extension I’m opening the file and grabbing some information from the file to save in the database. I have this model working. I’ve tested it in the built-in administration. It works.

Currently when there’s an error (it’s not an XML file; the file can’t be opened; a specific attribute doesn’t exist) I’m throwing an custom ‘Exception’ error. What I would like to do is some how pass these ‘Exception’ error messages to the view (whether that’s a custom view or the built-in administration view) and have an error message displayed like if the forms library was being used. Is that possible?

I’m starting to think I’m going to have to write the validation checks again using the forms library. If that’s the case, is it possible to still use the built-in administration template, but extend the form it uses to add these custom validations?

Anything to help my confusion would be appreciated.


UPDATE:

Here’s my model so far, for those who are asking, ‘nzb’ is the XML file field.
http://dpaste.com/hold/6101/

The admin interface will use the Form you associate with your model; your own views can also use the form.

This is exactly what I’d like to do. However, I don’t know how to associate my forms with my models. When ever I’ve created forms in the past they’ve always acted as their own entity. I could never get the administration views to use them while using the ModelForm class. Can you shead any light on this?

I’ve read over the link you gave me and it seams to be what I’ve done in the past, with no luck.

Getting attributes from the file, should probably be a method.

Sorry, could you please elaborate on this? A method where?


UPDATE:

It seams I’ve been compleatly missing this step to link a form to the administration view. http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin

This should now allow me to do the validation in a Form. However, I’m still confused about how to actually handle the validation. S.Lott says it should be a method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:21:39+00:00Added an answer on May 11, 2026 at 9:21 am

    The Form errors are automatically part of the administrative view.

    See http://docs.djangoproject.com/en/dev/ref/forms/validation/#ref-forms-validation

    You’re happiest if you validate in a Form — that’s what Forms are for. The admin interface will use the Form you associate with your model; your own views can also use the form.

    Getting attributes from the file, should probably be a separate method of the model class. The separate method of the model class can be used by the save() method of the model class or invoked at other times by view functions.


    ‘I could never get the administration views to use them while using the ModelForm class.’

    http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form

    http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin


    ‘I’m still confused about how to actually handle the validation. S.Lott says it should be a method?’

    Validation in a form is done with a clean() method or a clean_somefield() method.

    The ‘Adding custom validation to the admin’ link (above) shows how to add the clean_name method to the ‘MyArticleAdminForm’ form.

    If you’re still confused, trying actually typing the code from the Django web page and see what it does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 108k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You cannot write to XML with JavaScript, only load a… May 11, 2026 at 9:11 pm
  • Editorial Team
    Editorial Team added an answer You need to enter it as array (matrix) formula. After… May 11, 2026 at 9:11 pm
  • Editorial Team
    Editorial Team added an answer When you edit a QMainWindow you can right click the… May 11, 2026 at 9:11 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.