andersra
andersra

Reputation: 1135

Django model with Cloudinary Field

I am new to Python and playing around with Django. In my model I am trying to incorporate a field in my 'Product' model to have a Cloudinary image field.

I have added this to my settings.py:

# Cloudinary settings
CLOUDINARY = {
  'cloud_name': '[my_cloud_name]',  
  'api_key': '[my_api_key]',  
  'api_secret': '[my_api_secret]',  
}

Here is my models.py:

from django.db import models

    class Product (models.Model):
        name=models.CharField(max_length=200)
        image=cloudinary.models.CloudinaryField('image')
        description=models.TextField()

I have tried to import various things (import cloudinary, import cloudinaryField etc.

Not sure how to get my model to work. So far I have received the following errors through my various attempts:

  1. 'module' object has no attribute 'models'
  2. cannot import name CloudinaryField
  3. name 'cloudinary' is not defined

Can anyone help me out here? The documentation for Cloudinary is sparse, but I have read through it and hoping I did not miss a key step.

Thanks in advance!

Upvotes: 0

Views: 3189

Answers (1)

andersra
andersra

Reputation: 1135

I was able to solve this by adding the following to my models.py

import cloudinary
from cloudinary.models import CloudinaryField

Upvotes: 1

Related Questions