Reputation: 55
I don't exactly know how to diagnose this issue of mine, but I believe I have duplicate tables in my Postgres database. The reason I say this, is because When I go to my admin page, I see entries from my projects
table that are also part of the blog post
table. I want to separate these. I also found issues when trying to search through my blog. Here are the error messages:
Exception Type: VariableDoesNotExist
Exception Value: Failed lookup for key [username] in ''
This leads me to believe the search algorithm is having trouble looking through duplicates, especially since the blog posts
aren't even being found in my search results. Only project
objects are found.
How can I take a look into the Postgres database or further diagnose my issue?
EDIT Below is my models script:
from django.db import models
from mezzanine.blog.models import BlogPost, BlogCategory
# Create your models here.
class Projects(BlogPost):
pass
class ProjectsCategory(BlogCategory):
pass
These models inherit from the BlogPost
object offered by the Mezzanine CMS. I directly copied the views and made new Projects
objects with it.
Below is the search function provided by Mezzanine:
def search(request, template="search_results.html", extra_context=None):
"""
Display search results. Takes an optional "contenttype" GET parameter
in the form "app-name.ModelName" to limit search results to a single model.
"""
query = request.GET.get("q", "")
page = request.GET.get("page", 1)
per_page = settings.SEARCH_PER_PAGE
max_paging_links = settings.MAX_PAGING_LINKS
try:
parts = request.GET.get("type", "").split(".", 1)
search_model = apps.get_model(*parts)
search_model.objects.search # Attribute check
except (ValueError, TypeError, LookupError, AttributeError):
search_model = Displayable
search_type = _("Everything")
else:
search_type = search_model._meta.verbose_name_plural.capitalize()
results = search_model.objects.search(query, for_user=request.user)
paginated = paginate(results, page, per_page, max_paging_links)
context = {"query": query, "results": paginated,
"search_type": search_type}
context.update(extra_context or {})
return TemplateResponse(request, template, context)
Upvotes: 0
Views: 252
Reputation: 710
I see entries from my projects table that are also part of the blog post table
That's concerning but it may have just been a hiccup from the past. Generally speaking, it would require some directed effort to duplicate data from one table to another unrelated table with different columns.
Your database exists somewhere on the server machine, or it's on another server on the cloud, and that information would be probably located in your config files or be the default of localhost:5432
. If it's on your local machine or publicly accessible, you can log into it with a tool like DataGrip and browse the tables. Alternatively, you could use the shell on the machine it's located on to log in to postgres and run queries directly.
My guess is that this is not your issue and you can just delete the bad data.
For the search issue, We'd need to see the code to determine why it's not working. Can you add your models and search code?
Upvotes: 0