Note that there are some explanatory texts on larger screens.

plurals
  1. POExposing model method with Tastypie
    primarykey
    data
    text
    <p>I am currently working on implementing an API into my Django project and Tastypie seemed like it would be most suitable.</p> <p>What I can't seem to work out is how to expose a function within my model using Tastypie.</p> <p>For example, I have this model:</p> <pre><code>class game(models.Model): id = models.AutoField("ID", primary_key=True, editable=False) ip_address = models.OneToOneField(IPAddress, verbose_name="IP Address") port = models.CharField("Port", max_length=5) name = models.CharField("Game Name", max_length=100) ram = models.IntegerField("RAM (mb)", max_length=10) node = models.ForeignKey(node) user = models.ForeignKey(User) config = models.ForeignKey(Config) mysqlserver = models.ForeignKey(MySQLserver) mysqlenabled = models.BooleanField("MySQL Created?") suspended = models.BooleanField("Suspended") </code></pre> <p>And within this model, I have functions such as this:</p> <pre><code>def start(self): config = Config.objects.get(pk=self.config.id) cmds = config.startcmds game = config.gametype parsedcmds = self.replace_variables(cmds) client = phPanel.jelly.jelly.zmqclient(self.ip_address.address) data = {'user':self.generate_username(), 'method':'start_server', 'id':self.id, 'memory':self.ram, 'ip':self.ip_address.address, 'port':self.port, 'startcmds':parsedcmds, 'game':game} result = client.send(data) return result </code></pre> <p>which I would like to expose through the API using tastypie.</p> <p>I've looked through the documentation and the cookbook but I can't seem to find what I am looking for.</p> <p>Any help would be appreciated :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload