I have my django apps inside apps folder. Due to multiple article types I decided to split my models.py for the articles app and put it inside the models folder where each modelname.py file points to a model.
Problem: configuring syndication framework (as described in https://docs.djangoproject.com/en/3.2/ref/contrib/syndication/) causes a runtime error Conflicting 'news' models in application 'articles': <class 'articles.models.news.News'> and <class 'apps.articles.models.news.News'>.
Note: Before adding syndication framework functionality everything works just fine.
I tried: Adding app_label to the News model.
apps folder structure:
├── articles
│ ├── admin.py
│ ├── apps.py
│ ├── feeds.py
│ ├── __init__.py
│ ├── models
│ │ ├── __init__.py
│ │ ├── articles.py
│ │ ├── categories.py
│ │ ├── news.py
│ │ ├── reviews.py
│ │ └── tags.py
│ ├── tests.py
│ ├── urls.py
│ └── views
│ ├── __init__.py
│ ├── news.py
├── conftest.py
├── education
├── __init__.py
├── users
/apps/articles/models/news.py:
from django.db import models
class News(models.Model):
//
// Model Fields
//
class Meta:
...
app_label = 'articles'
...
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("articles:news_detail", kwargs={"slug": self.slug})
/apps/articles/feeds.py:
from django.contrib.syndication.views import Feed
from django.utils.translation import gettext_lazy as _
from .models.news import News
class NewsEntriesFeed(Feed):
title = _("News")
link = "/news/"
description = _("Latest news")
def items(self):
return News.objects.order_by('-publish_date')[:5]
def item_title(self, item):
return item.title
def item_description(self, item):
return item.lead
/apps/articles/urls.py:
from django.urls import path
from .views.news import NewsDetailView, NewsListView
from .feeds import NewsEntriesFeed
app_name = "articles"
urlpatterns = [
path("news/", NewsListView.as_view(), name="news_list"),
path("news/<str:slug>/", NewsDetailView.as_view(), name="news_detail"),
path("feed/rss", NewsEntriesFeed(), name="news_feed"),
]
/apps/articles/apps.py
from django.apps import AppConfig
class ArticlesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'articles'
INSTALLED_APPS
INSTALLED_APPS = [
...
...
"apps.articles.apps.ArticlesConfig",
...
]