I have searched and tried everything but cannot get my csv file to populate and show up in Django Admin. Please note all the files below are in the same directory, including the csv.
Here is my models.py
from django.db import models
class Album(models.Model):
artist = models.CharField(max_length=100)
album_title = models.CharField(max_length=100)
genre = models.CharField(max_length=100)
album_logo = models.CharField(max_length=1000)
def __str__(self):
return self.album_title + ' - ' + self.artist
class Meta:
verbose_name_plural = 'Album'
and here is my import.py file:
import csv
from music.models import Album
with open('names.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
artist = row['artist']
album_title = row['album_title']
genre = row['genre']
album_logo = row['album_logo']
new_album = Album(artist=artist, album_title=album_title, genre=genre, album_logo=album_logo)
new_album.save()
I run the server and Admin has the table and database, but it's not populated with my csv file's data. Any help would be appreciated. Thank you.