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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:43:41+00:00 2026-06-11T23:43:41+00:00

I have a string sentence structure such as this: Starting in $Duration%, the $Noun$

  • 0

I have a string sentence structure such as this:

Starting in $Duration%, the $Noun$ will be $Adjective$

I need a view to check which words are in “$$” and replace them with a random word from the database which was imported from a SQL file.

Here are the models/sql files:

from django.db import models
from django.utils import timezone

class Type(models.Model):
    type = models.CharField(max_length=50)
    value = models.CharField(max_length=1)


class Word(models.Model):
    dict = models.CharField(max_length=200)
    kind = models.CharField(max_length=1)

    def randword(self):
        words = self.objects.all()
        number = randrang(0,len(words))
        return words[number]


class Question(models.Model):
    question = models.CharField(max_length=200)

    def randquest(self):
        quests = self.objects.all()
        numbeq = randrang(0, len(quests))
        return quests[numbeq]


class Meta(models.Model):
    question = models.ForeignKey(Question)
    score = models.ForeignKey("Score")
    user = models.CharField(max_length=200)
    time = models.DateTimeField('date published')


class Score(models.Model):
    word = models.ForeignKey(Word)
    score = models.IntegerField()
    question = models.ManyToManyField(Question, through=Meta)

    def __unicode__(self):
        return self.score

SQL files

INSERT INTO quest_question (question) VALUES ('Starting in $Duration$, the $Noun$ will be $Adjective$');

and

INSERT INTO quest_word (dict, kind) VALUES ('Coffee Maker', '1');
INSERT INTO quest_word (dict, kind) VALUES ('24 hours', '3');
INSERT INTO quest_word (dict, kind) VALUES ('today', '3');
INSERT INTO quest_word (dict, kind) VALUES ('broken', '2');
INSERT INTO quest_word (dict, kind) VALUES ('Email server', '1');
INSERT INTO quest_word (dict, kind) VALUES ('15 minutes', '3');
INSERT INTO quest_word (dict, kind) VALUES ('tomorrow', '3');
INSERT INTO quest_word (dict, kind) VALUES ('unavailable', '2');


INSERT INTO quest_type (type, value) VALUES ('Noun', '1');
INSERT INTO quest_type (type, value) VALUES ('Adjective', '2');
INSERT INTO quest_type (type, value) VALUES ('Duration', '3');

I started writing the view. Need some help with it:

from quest.models import Word, Type, Score, Question, Meta
from django.utils import timezone


def question(request):
    sentence = Question.objects.all()
    find_words = re.findall(r"\w+%0-9a-zA-Z%", sentence.question)
  • 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-11T23:43:42+00:00Added an answer on June 11, 2026 at 11:43 pm

    If you’re willing to change the notation, you have two options:

    1. Use Python.

      >>> 'Starting in {Duration}, the {Noun} will be {Adjective}'.format(Duration='24 hours', Noun='Coffee Maker', Adjective='broken')
      'Starting in 24 hours, the Coffee Maker will be broken'
      >>> 'Starting in %(Duration)s, the %(Noun)s will be %(Adjective)s' % dict(Duration='24 hours', Noun='Coffee Maker', Adjective='broken')
      'Starting in 24 hours, the Coffee Maker will be broken'
      
    2. Use Django.

      >>> from django.template import Context, Template
      >>> t = Template('Starting in {{Duration}}, the {{Noun}} will be {{Adjective}}') 
      >>> c = Context(dict(Duration='24 hours', Noun='Coffee Maker', Adjective='broken'))
      >>> t.render(c)
      u'Starting in 24 hours, the Coffee Maker will be broken'
      

    The rest is pulling from the database and selecting the words at random, which is the easy part.

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

Sidebar

Related Questions

I have a varargs constructor like this : public class Sentence { public String[]
I have string as abvd.qweqw.sdfs.a=aqwrwewrwerrew . I need to parse this string and get
I have a string that is a sentence, written in chinese. This contains chinese
I have a string like this: inputString = this is the first sentence in
I would like to have a function which takes 3 arguments: sentence (string), maxCharLen=20
If I have a string of garbage like this is a sentence that is
I have a string which contains a sentence and I want to split it
I have a String variable (basically an English sentence with an unspecified number of
I have a collection of IEnumerable<sentence> (sentence = string) I want to split all
I have string that look like Array that fetched from other webservice like this

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.