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 8847783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:16:25+00:00 2026-06-14T12:16:25+00:00

I have a model that can access Api and return json data class Video(models.Model):

  • 0

I have a model that can access Api and return json data

class Video(models.Model):
   url = models.URLField(_('URL'), blank=True)
   type = models.CharField(max_length=10, null=True, blank=True)

   def get_oembed_info(self, url):
      api_url = 'http://api.embed.ly/1/oembed?'
      params = {'url': url, 'format': 'json'}
      fetch_url =  'http://api.embed.ly/1/oembed?%s' % urllib.urlencode(params)
      result = urllib.urlopen(fetch_url).read()
      result = json.loads(result)
      return result

  def get_video_info(self):
     url = self.url
     result = self.get_oembed_info(url)
     KEYS = ('type', 'title', 'description', 'author_name')
     for key in KEYS:
       if result.has_key(key):
          setattr(self, key, result[key])

  def save(self, *args, **kwargs):
     if not self.pk:
        self.get_video_info()

     super(Video, self).save(*args, **kwargs)

class VideoForm(forms.ModelForm):
  def clean(self):
    if not self.cleaned_data['url'] and not self.cleaned_data['slide_url']:
      raise forms.ValidationError('Please provide either a video url or a slide url')
    return self.cleaned_data

I want to access the type field while submitting the form, so if the type is other than “something” raise an Error like in the above clean method. Or how can I access get_oembed_info method result in VideoForm Class.

Solution

Well as Thomas said to call the model’s clean method and then do the magic

def clean(self):
   self.get_video_info()
   if self.type == 'something':
      raise ValidationError("Message")
  • 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. Editorial Team
    Editorial Team
    2026-06-14T12:16:26+00:00Added an answer on June 14, 2026 at 12:16 pm

    A ModelForm is going to going to call your model’s clean method during its validation process. That method can raise ValidationError‘s which will be added to your form’s errors.

    You could therefore implement your validation logic in your model’s clean method, where the get_oembed_info method is available using self.get_oembed_info().

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

Sidebar

Related Questions

In my controller I have model operations that can return empty results. I've setup
In a client application I have a DBIx::Class model 'Todo' that can be linked
Does jquery/javascript have any event model that you can attach to your objects? Basically
How can I override the IsValid property? I have a model that's validating as
I want to have a model with calculated fields that I can apply sorting
As it stands, I have a deserialiser that can import any model I throw
I have a class that adapts std::vector to model a container of domain-specific objects.
I have model/controller called notification. I want to make a new url so that
I'd like to have read-only access to model's attributes (:test) that is related to
I have an application that can be viewed with landscape and portrait mode. I'm

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.